1

I am using web3 and Metamask in chrome. I'd like to get all accounts connected to my website with below code:

ethereum.request({
      method: 'eth_accounts',
    });

I have created two accounts in Metamask and connected both of them to this website. However, the above code only return the current selected accounts. Is there a way to get all connects from the wallet?

3 Answers 3

2

Due to privacy reasons, Metamask currently cannot return all the connected accounts.

See: https://stackoverflow.com/questions/68356216/metamask-multiple-getting-all-connected-accounts

1

It seems wallet_getPermissions does that:

ethereum
   .request({method: 'wallet_getPermissions'})
   .then(res => {
      console.log('Connected accounts:', res[0]?.caveats?.[0]?.value);
   })
   .catch(err => {
     console.log('Error getting permissions:', err);
   });

I'm not sure how reliable this is but it does return array of connected accounts.

1
0

I'm not sure that you can since the "connection" of metamask to your website is kept on the metamask side, not the website side.

But you can have your backend look at the address and check in the database if that address is a new user, and if yes then you just save that address into your DB.

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.