我想获取用户在 Metamask 中添加的所有帐户。我尝试了所有 web3.js 方法来获取帐户,但我总是只得到一个帐户,该帐户始终是当前选定的帐户。
根据 web3.js 文档,web3.eth.getAccounts()
应返回此节点控制的所有帐户。但是,我得到了一个只有当前选择的数组。不用说,我在 Metamask 中创建了多个帐户。
最佳答案
文档说:Account List Reflects User Preference
When a user selects an account in MetaMask, that account silently becomes the
web3.eth.accounts[0]
in your JS context, the only member of theweb3.eth.accounts
array.
我猜这取决于默认情况下 MetaMask 使用的 web3 提供商。结帐 Why does web3.eth.getAccounts() return only 1 account?问题以查看某些提供程序返回多个帐户,这取决于配置。
关于ethereum - 从 Metamask 获取所有以太坊账户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976890/