web3.eth.getTransaction with ganache-cli gives chainId error

Viewed 1156

When ganache calls eth_getTransactionByHash I get this error - "UnhandledPromiseRejectionWarning: Error: Incompatible EIP155-based V 1 and chain id 1. See the second parameter of the Transaction constructor to set the chain id." Other web3 calls are working fine. This is how I'm calling the web3 function to get a transaction

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

and this is how I'm running ganache

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

I've seen other people having this issue and it's a ganache issue but none of the solutions worked for me and I haven't seen it for eth_getTransactionByHash. I've tried passing a chain id however that hasn't done anything either. Thanks!

1 Answers

Add "gasPrice": w3.eth.gas_price to the buildTransaction function and change to 1337 chainID in ganache server settings.

Example:

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