[英]web3.eth.getAccounts(); current not working
I have five accounts set up on Metamask, from Ganache.我在来自 Ganache 的 Metamask 上设置了五个帐户。
I've selected one with 1000 test Ether.我选择了一个有 1000 个测试以太币的。
But...但...
const accounts = await web3.eth.getAccounts();
const account = accounts[0];
accounts
is always an array of length one. accounts
始终是长度为 1 的数组。
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. Metamask 让您只连接一个帐户,因此您的帐户数组的长度始终为 1。 See this topic: https://github.com/MetaMask/metamask-extension/issues/5607
请参阅此主题: 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您需要在 Metamask 中更改帐户后重新加载页面,以便考虑或处理第三个答案中建议的更改帐户事件: https://ethereum.stackexchange.com/a/63823
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.