Skip to main content
added 528 characters in body
Source Link

Maybe a good option is toI think you can use ethereum.isConnected()the Provider and see how many accounts you have and from there if you have 0 accounts you can think that the user has not connected any account. Take account this example:

function handleAccountsChanged(accounts) {
  if (accounts.length === 0) {
   // MetaMask is locked or the user has not connected any accounts
   console.log('Please connect to MetaMask.');
  } else if (accounts[0] !== currentAccount) {
    currentAccount = accounts[0];
    // Do any other work!
  }
}

More detailsYou can see more complete info as an example here: https://docs.metamask.io/guide/ethereum-provider.html#methodshttps://docs.metamask.io/guide/ethereum-provider.html#using-the-provider

Maybe a good option is to use ethereum.isConnected().

More details here: https://docs.metamask.io/guide/ethereum-provider.html#methods

I think you can use the Provider and see how many accounts you have and from there if you have 0 accounts you can think that the user has not connected any account. Take account this example:

function handleAccountsChanged(accounts) {
  if (accounts.length === 0) {
   // MetaMask is locked or the user has not connected any accounts
   console.log('Please connect to MetaMask.');
  } else if (accounts[0] !== currentAccount) {
    currentAccount = accounts[0];
    // Do any other work!
  }
}

You can see more complete info as an example here: https://docs.metamask.io/guide/ethereum-provider.html#using-the-provider

Source Link

Maybe a good option is to use ethereum.isConnected().

More details here: https://docs.metamask.io/guide/ethereum-provider.html#methods