I tried connecting metamask wallet with web3.js, and it got succeeded.

const handleClick = async () => {
    try {
      // Get network provider and web3 instance.
      const web3 = await GetWeb3();
      // console.log(web3);

      // Use web3 to get the user's accounts.
      const accounts = await web3.eth.getAccounts();

      // Get the contract instance.
      const networkId = await web3.eth.net.getId();
      const deployedNetwork = smartContract.networks[networkId];
      const instance = new web3.eth.Contract(
        deployedNetwork && deployedNetwork.address

      if (accounts) {
          type: "WALLET_CONNECT",
          payload: {
            isWalletConnected: true,
            web3: web3,
            accounts: accounts,
            contract: instance,


      console.log(web3, accounts, instance);
    } catch (error) {
        `Failed to load web3, accounts, or contract. Check console for details.`

Now I would like to disconnect metamask wallet from the dapp, when the disconnect button is clicked, just like a logout button. Can anyone help me with this?

1 Answer 1


It's not possible.

Dapp's which have a "disconnect" button didn't actually disconnecting metamask. You are able to see that in Metamask interface still displays connected even after clicking logout.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.