简体   繁体   English

如何使用以太坊从 reactjs 中的元掩码帐户注销

[英]How to logout from metamask account in reactjs using etherum

I am unable to disconnect from metamask account.我无法断开与元掩码帐户的连接。 I am attaching the code snippet.我附上代码片段。

export const logoutUser = () => {
if (window.ethereum && window.ethereum.isMetaMask) {
    window.ethereum.on('accountsChanged', function (accounts) {
        return () => window.ethereum.removeListener('accountsChanged', accounts);
      });
    
}

} }

As of now, you cannot logout metamask by web3 or ethereum api.截至目前,您无法通过 web3 或以太坊 api 注销元掩码。 you have to manually disconnect metamask.您必须手动断开元掩码。

accountChanged listener will just detect if metamask connects to a different account. accountChanged监听器只会检测元掩码是否连接到不同的帐户。

As of now we can't disconnect from Metamask from our app, but what developers do is to remove/add the information of that Metamask account in a variable inside that app by pressing the disconnect/connect button.到目前为止,我们无法从我们的应用程序中断开 Metamask,但开发人员所做的是通过按下断开/连接按钮在该应用程序内的变量中删除/添加该 Metamask 帐户的信息。

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

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