Metamask has a button disconnect, that if pushed by the user, will requrie the app to re-enable the provider.
DApp should be able to react to that the same way they are able to react to network changed or wallet changed.
@rekmarks can you give the ERC standard perspective on this
Hi @Amxx, hope you are well! My answer will probably be more thorough than you require it to be, for the benefit of anyone stumbling across this issue.
MetaMask already emits an event in the case you described: accountsChanged. It emits with an array that is either empty or has at least one account in it (today only ever one, but soon also multiple). If the user revokes access to their account(s), the accountsChanged event will be emitted with [].
accountsChanged is also emitted with [] if MetaMask becomes locked. This particular case can be identified by calling the non-standard asynchronous method ethereum._metamask.isUnlocked(), perhaps in the accountsChanged listener callback.
In light of recent updates to the provider API via EIP 1193, there's one more thing I want to clear up. In our UI, connected/disconnected refers to whether a dapp has access to one or more of the user's accounts. In the provider specification, connected/disconnected refers to whether the Provider can send RPC requests to its chain(s) or not. MetaMask's provider therefore will emit the event disconnect in our next release, but it will not have anything to do with the user's accounts.
I'll close this issue for now, but please feel free to reach out with any further questions or comments.
Most helpful comment
Hi @Amxx, hope you are well! My answer will probably be more thorough than you require it to be, for the benefit of anyone stumbling across this issue.
MetaMask already emits an event in the case you described:
accountsChanged. It emits with an array that is either empty or has at least one account in it (today only ever one, but soon also multiple). If the user revokes access to their account(s), theaccountsChangedevent will be emitted with[].accountsChangedis also emitted with[]if MetaMask becomes locked. This particular case can be identified by calling the non-standard asynchronous methodethereum._metamask.isUnlocked(), perhaps in theaccountsChangedlistener callback.In light of recent updates to the provider API via EIP 1193, there's one more thing I want to clear up. In our UI, connected/disconnected refers to whether a dapp has access to one or more of the user's accounts. In the provider specification, connected/disconnected refers to whether the Provider can send RPC requests to its chain(s) or not. MetaMask's provider therefore will emit the event
disconnectin our next release, but it will not have anything to do with the user's accounts.I'll close this issue for now, but please feel free to reach out with any further questions or comments.