【问题标题】:web3.eth.getTransaction with ganache-cli gives chainId error带有 ganache-cli 的 web3.eth.getTransaction 给出了 chainId 错误
【发布时间】:2021-11-28 17:50:23
【问题描述】:

当 ganache 调用 eth_getTransactionByHash 时,我收到此错误 - “UnhandledPromiseRejectionWarning:错误:基于 EIP155 的 V 1 和链 id 1 不兼容。请参阅事务构造函数的第二个参数来设置链 id。”其他 web3 调用工作正常。这就是我调用 web3 函数来获取交易的方式

web3.eth.getTransaction('<txn-hash>')
  .then(result => {
    console.log('result: ', result);
  }).catch(err => {
    console.log('error: ', err);
  })

这就是我运行 ganache 的方式

ganache-cli --fork https://mainnet.infura.io/v3/<project-id>

我见过其他人有这个问题,这是一个 ganache 问题,但没有一个解决方案对我有用,我也没有看到 eth_getTransactionByHash。我试过传递一个链 ID,但它也没有做任何事情。谢谢!

【问题讨论】:

    标签: node.js blockchain ethereum web3js ganache


    【解决方案1】:

    "gasPrice": w3.eth.gas_price添加到buildTransaction函数并在ganache服务器设置中更改为1337 chainID

    例子:

    transaction = SimpleStorage.constructor().buildTransaction(
        {
            "chainId": chain_ID,
            "from": my_address,
            "nonce": nonce,
            "gasPrice": w3.eth.gas_price,
        }
    )
    

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2022-01-01
      • 2022-01-03
      • 1970-01-01
      • 2022-06-15
      • 2022-06-23
      • 2022-08-31
      • 2020-01-29
      • 2020-08-28
      相关资源
      最近更新 更多