如何连接确定我在 Ganache 中连接的网络
我试过了 const networkId = await Web3.eth.net.getId()
但我得到的错误是这个
未处理的拒绝(TypeError):无法读取未定义的属性“net”
答案 0 :(得分:0)
由于您使用带有大写 Web3
的 W
,我假设它是类的名称 - 而不是实例。
您需要访问实例属性 net
及其方法 getId()
。
// instantiate the class first
const web3 = new Web3();
// mind the lowercase `w` in `web3`, accessing the instance
const networkId = await web3.eth.net.getId();