0

When attempting a contract function call in hardhat using ethers the call reverts as the to field in the call is set to null as shown below:

Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0xafd5a04c04c4fed1120b670622412269f2137170bac283412a2a3729722530c8", transaction={"hash":"0xafd5a04c04c4fed1120b670622412269f2137170bac283412a2a3729722530c8","type":0,"accessList":null,"blockHash":"0x8e948beb340aabcb01b7f98a7ca38411cde51d2fb432ec8b27bc8692e1ca7e5f","blockNumber":378,"transactionIndex":2,"confirmations":2,"from":"0x...","gasPrice":{"type":"BigNumber","hex":"0x48"},"gasLimit":{"type":"BigNumber","hex":"0x060186"},"to":null,"value":{"type":"BigNumber","hex":"0x00"},"nonce":67,"data":"0x...","r":"0x75e4b2891795169c1bc0751c1f4be5b3c12f81ab637247c8643bfdc0d059bb37","s":"0x25dc54be770443463de1146ab44181fc8575b47341e3e4d127a78bddfaf8a134","v":1,"creates":"0x01325512e9C9b61872fc26C54C14B7a4A20C9904","chainId":296}, receipt={"to":null,"from":"0x...","contractAddress":null,"transactionIndex":2,"gasUsed":{"type":"BigNumber","hex":"0x060186"},"logsBloom":"0x","blockHash":"0x8e948beb340aabcb01b7f98a7ca38411cde51d2fb432ec8b27bc8692e1ca7e5f","transactionHash":"0xafd5a04c04c4fed1120b670622412269f2137170bac283412a2a3729722530c8","logs":[],"blockNumber":378,"confirmations":2,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x060186"},"effectiveGasPrice":{"type":"BigNumber","hex":"0xa7a3582000"},"status":0,"type":0,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.6.8)

NB: 0x... is used as a placeholder.

const tx = await contractInstance.contractFunction(contractParameter);
await tx.wait();

The issue is seemingly non-deterministic and occurs only on certain calls with certain. Why is this so?

1 Answer 1

0

It seems to be a gasLimit issue, looking at the gasLimit in the revert error of {"type":"BigNumber","hex":"0x060186"} or 393606, appears to be insufficient to complete the transaction as increasing the gasLimit in the function call overrides does not revert. It's possible that ethers does an eth_estimateGas prefetch call if a gasLimit isn't provided in the function overrides and uses the result of that call for the gasLimit, however if that call fails ethers may use the hardcoded gasLimit of 360_000 which is less than the required gasLimit of 393606, however also if the eth_estimateGas call fails ethers does not initialise to to the contract address for the main eth_call hence its values is null

const tx = await contractInstance.contractFunction(contractParameter, {gasLimit: 400_000});
await tx.wait();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.