如何从Metamask获取帐户地址?

时间:2019-06-23 02:50:19

标签: ethereum solidity web3

accounts[0]在此代码中返回undefined

const accounts = await web3.eth.getAccounts()
console.log(accounts[0])

我卸载了Metamask并重置了帐户,但这没用。

web3版本为web3@1.0.0-beta.37

您能给我什么建议,为什么我不能从Metamask获取帐户地址吗?

1 个答案:

答案 0 :(得分:0)

存在Metamask连接错误。 我通过编码连接到了web3。

Web3(window.web3.currentProvider)

但是,此代码更适合现代钱包。

web3 = new Web3(window.ethereum)
    window.ethereum.enable().catch(error => {
        // User denied account access
        console.log(error)
    })
相关问题