I have five accounts set up on Metamask, from Ganache.
I've selected one with 1000 test Ether.
But...
const accounts = await web3.eth.getAccounts();
const account = accounts[0];
accounts
is always an array of length one.
Why is that?
Also the account in the array is the first account, NOT the currently selected one.
Is there something I am missing this how this works? Thanks.
Metamask let you connect only one account so your accounts array will always be of length one. See this topic: https://github.com/MetaMask/metamask-extension/issues/5607
You need to reload the page after changing account in Metamask for it to be considered or handle the change account event as suggested here in the 3rd answer: https://ethereum.stackexchange.com/a/63823
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.