繁体   English   中英

如何确定我在 Ganache 中连接的网络

[英]How do I determine the network i am connected to in Ganache

如何连接确定我在 Ganache 中连接的网络

我试过这个 const networkId = await Web3.eth.net.getId()

但我得到的错误是这个

未处理的拒绝(TypeError):无法读取未定义的属性“网络”

由于您使用带有大写WWeb3 ,我假设它是 class 的名称 - 而不是实例。

您需要访问实例属性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(); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM