简体   繁体   English

如何仅将我的 web3 应用程序连接到 Meta Mask 钱包

[英]How to connect my web3 app only to Meta Mask wallet

I am trying to build an app with web3js.我正在尝试使用 web3js 构建一个应用程序。 I use JavaScript for connecting the app to wallet.我使用 JavaScript 将应用程序连接到钱包。

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.但现在我只想连接 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 .您可以针对window.ethereum.isMetaMask进行验证。

There is a high probabiliy of other wallets not setting this property and not returning true .其他钱包很可能没有设置这个属性并且没有返回true

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 React 上的 bsc 测试网上将 Metamask 钱包地址连接到 web3 - How to connect Metamask wallet address to web3 on bsc testnet on React angular uing web3中如何连接钱包MetaMask? - How to connect with wallet MetaMask in angular uing web3? Wallet Connect / Web3 Provider 仅通过 imoprting 显示很多错误 - Wallet Connect / Web3 Provider showing a lot of errors just by imoprting 如何通过 web3 或其他人获取 Metamask 钱包中的所有代币? - How do I get all the tokens inside my Metamask wallet by web3 or others? 检查 web3 钱包是否已解锁 - Check if web3 wallet is unlocked Metamask (web3) 连接钱包并发送交易 - 如何将区块链更改为 Bianance 智能链 (BEP-20) 网络而不是以太坊? - Metamask (web3) connect wallet and send transaction - how to change blockchain to Bianance smart chain (BEP-20) network instead of Ethereum? 如何使用 web3 获取钱包中的所有地址? - how i can get all the addresses in wallet using web3? Web3:访问 MetaMask 钱包中的私钥 - Web3: accessing private key in MetaMask wallet Web3 库 Javascript - getAccounts 与 accounts.wallet[0] - Web3 Library Javascript - getAccounts vs accounts.wallet[0] 如何使用 Web3.js 通过 Solana Pay 连接虚拟钱包? - How to connect phantom wallet by Solana Pay using Web3.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM