ethereum - 从 Metamask 获取所有以太坊账户

标签 ethereum web3 metamask

我想获取用户在 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 the web3.eth.accounts array.



我猜这取决于默认情况下 MetaMask 使用的 web3 提供商。结帐 Why does web3.eth.getAccounts() return only 1 account?问题以查看某些提供程序返回多个帐户,这取决于配置。

关于ethereum - 从 Metamask 获取所有以太坊账户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976890/

相关文章:

python-3.x - Runtime.callFunctionOn 抛出异常 : Error: LavaMoat - property "Proxy" of globalThis is inaccessible under scuttling mode

blockchain - 如何在没有元掩码的情况下创建 DAPP

react-native - 在 React Native 应用程序上没有远程调试器时无法调用 web3.eth.accounts.create()

ubuntu - 如何在 Ubuntu 上安装 web3?

bash - Istanbul-tools 安装错误 : github. com/ethereum/go-ethereum/crypto/bn256/cloudflare.gfpMul : relocation target runtime. support_bmi2 not defined

websocket - 如何在 BSC 上获取待处理的交易

ubuntu - 无法在 ubuntu 18.04 中安装 web3

testing - 使用 Metamask 进行测试的 Cypress 测试方法

java - 如何使用java从solidity合约中获取值(value)

bitcoin - 区 block 链是去中心化数据库吗?