【问题标题】:How do I determine the network i am connected to in Ganache如何确定我在 Ganache 中连接的网络
【发布时间】:2021-08-24 13:05:58
【问题描述】:

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

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

但我得到的错误是这个

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

【问题讨论】:

    标签: blockchain solidity metamask ganache


    【解决方案1】:

    由于您使用 Web3 和大写 W,我假设它是类的名称 - 而不是实例的名称。

    你需要访问instance属性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(); 
    

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多