gpt4 book ai didi

ethereum - 如何从 Metamask 获取帐户地址?

转载 作者:行者123 更新时间:2023-12-04 01:42:39 25 4
gpt4 key购买 nike

accounts[0]返回 undefined在这段代码中。

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

我卸载了 Metamask 并重置了帐户,但这不起作用。

web3 版本是 web3@1.0.0-beta.37 .

你能给我任何建议,为什么我无法从 Metamask 获得账户地址?

最佳答案

出现 Metamask 连接错误。
我通过编码连接到 web3。

Web3(window.web3.currentProvider)

但是,此代码更适合现代钱包。
web3 = new Web3(window.ethereum)
window.ethereum.enable().catch(error => {
// User denied account access
console.log(error)
})

关于ethereum - 如何从 Metamask 获取帐户地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56720654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com