简体   繁体   中英

How to connect my web3 app only to Meta Mask wallet

I am trying to build an app with web3js. I use JavaScript for connecting the app to wallet.

const accounts = await web3.eth.requestAccounts().catch((error) => {
    $('#walletErrorMsg').html(error.message);
    $('#walletErrorModal').modal('show');
});

This is my code to connect app to wallet. This code works perfectly. But now I want to connect only with MetaMask. No support for other wallets. How can I connect only with meta mask ? Is there any solution for this? Thanks in advance.

You can validate against window.ethereum.isMetaMask .

There is a high probabiliy of other wallets not setting this property and not returning true .

Docs: https://docs.metamask.io/guide/ethereum-provider.html#ethereum-ismetamask

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM