web3jsmetamask

How to prompt connecting another wallet via Web3.js


I'm building a dapp that allows users to connect multiple wallets. When a user is not connected to my app at all and I issue the const accounts = await this.eth.request({ method: 'eth_requestAccounts' }); call, MetaMask pops up the connect dialog as expected. However, if a user is already connected with a different wallet I am unable to get that to pop up again on MetaMask so the user can authorize the connection additional wallets. Is there a programmatic way to get MetaMask to display the connect dialog so the user can add the wallet they currently have selected in MetaMask?


Solution

  • You can't disconnect a wallet programmatically or request a "wallet disconnection" just like you do with eth_requestAccounts, unfortunately.

    dApps that seem to have this functionality just simulate it. See this other answer, for example, where they explain that: How to Logout of MetaMask account Using web3.js

    But, going back to your issue, it must be the user who disconnects the wallet. Once they do that, they can connect a new one.