Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to initiate a disconnect request to the Metamask wallet?

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.

like image 730
vladwho Avatar asked Mar 30 '21 07:03

vladwho


People also ask

Can you disconnect a wallet from MetaMask?

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 do I remove MetaMask from another device?

How to disconnect Metamask. First, click your address in the upper right corner of the page. Then, click "disconnect".


2 Answers

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.

like image 194
Afr Avatar answered Oct 21 '22 05:10

Afr


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: {}}]
})
like image 3
Stéphane Le Solliec Avatar answered Oct 21 '22 07:10

Stéphane Le Solliec