Disconnect wallet from site using web3

Viewed 2273

I am using web3 to connect to metamask using below method

await window.ethereum.request({ method: 'eth_requestAccounts' });
var address = await window.ethereum.request({ method: 'eth_accounts' });

but when i am refreshing screen it still shows as connected, i am not able to find any method in web3 to disconnect it from website like pancackeswap have

1 Answers

It is an ongoing open issue with metamask as far as I know and this solution will only disconnect the first profile without a popup, save the isReturningUser variable in local storage and update accordingly to control function logic flow.

const walletAddress = await window.ethereum.request({
      method: "eth_requestAccounts",
      params: [
        {
          eth_accounts: {}
        }
      ]
    });

    if (!isReturningUser) {
    // Runs only they are brand new, or have hit the disconnect button
      await window.ethereum.request({
        method: "wallet_requestPermissions",
        params: [
          {
            eth_accounts: {}
          }
        ]
      });
    }
Related