I'm building a decentralized application where users can connect their cryptocurrency wallet (Metamask) to my website.
They can initiate a connection request by clicking a button. On success, the wallet is connected and my website can interact with it.
Is there any way to initiate a disconnect request? Similar to a 'Log out' button. Currently, the users have to manually disconnect their wallet within Metamask settings which is not a straightforward process.
However, it is easy to disconnect your wallet from a website. On the main page of your MetaMask account, there are three dots in the top right hand corner. This will open an expanded menu that will give you four options.
How to disconnect Metamask. First, click your address in the upper right corner of the page. Then, click "disconnect".
Not the answer you might be hoping for: It's not possible.
The connect/disconnect functionality is entirely in the user's hands due to security and privacy concerns. You can kindly ask the wallet to prompt the user to connect to the website, but there is no functionality to prompt the user to disconnect.
Programmatically resetting the accounts array does not disconnect the wallet even though some implementations such as Pancake Swap suggest this is the case; they simply pretend a disconnect.
Here is what I use to disconnect your connected account (assuming you have only one) from the application:
await window.ethereum.request({
method: "eth_requestAccounts",
params: [{eth_accounts: {}}]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With