blockchain - 如何确定我在 Ganache 中连接的网络
问题描述
如何连接确定我在 Ganache 中连接的网络
我试过这个 const networkId = await Web3.eth.net.getId()
但我得到的错误是这个
未处理的拒绝(TypeError):无法读取未定义的属性“网络”
解决方案
由于您使用的是Web3
with capital 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();
推荐阅读
- reactjs - Azure Devops - 部署 React 应用程序 - 错误 - ENOENT:没有这样的文件或目录,符号链接'../detect-port-alt/bin/detect-port'
- reactjs - 使用 react-testing 库测试到达路由器的导航
- python - AttributeError:“PngImageFile”对象没有属性“形状”
- rust - 如何在 rust/tokio 的 TCP 客户端绑定()?
- javascript - 如何为单选按钮添加答案?
- mysql - 如何从多个表中删除数据?
- c++ - 当 Vector 超出范围时,系统调用参数 read(buf) 指向不可寻址字节
- python - 有没有办法使用 Selenium 在线上传 .pdf 文件?
- mysql - 连接关闭错误后不允许操作的原因?
- c# - Bot 在 Web 客户端中启动时不欢迎用户加入