[英]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.