I have a call to estimateGas from an Express server to a private Hyperledger Besu chain and everything was working fine yesterday, yet today when I run the same method it's returning "Error: Returned error: Internal error". Nothing changed in the code between yesterday and today, and I'm lost as to where to even start troubleshooting.
That is the extent of the error, nothing more descriptive is given, and after googling for hours, I haven't found anything that could help. The stack trace points to the error handler file in the web3 node module.
Code (actual methods and parameters omitted for security reasons):
console.log("Estimating Gas");
let gas = await this.myContract.methods
.myMethod(
address,
uint256,
address,
address,
uint256
)
.estimateGas({ from: address });
console.log("This call will probably take " + gas + " gas");
Expected behavior: return amount of estimated gas
Actual behavir: Logs the first message, but returns internal error caught from estimateGas method, and never makes it to the second message
Does anyone know how I can retrieve a more specific error or how to fix it?
It can be a problem on your web3 provider, but more likely option is that executing of the myMethod()
would result in reverting the transaction - that's why it probably throws the error.
You can encapsulate the method in a try/catch block to catch the error message.
try {
let gas = await this.myContract.methods
.myMethod(
address,
uint256,
address,
address,
uint256
)
.estimateGas({ from: address });
} catch (err) {
console.log(err);
}
It can return a specific revert message that you can validate against your Solidity code with the require()
statement that defines this message.
Or it returns the generic "gas required exceeds allowance", which can be caused by any failing require
/assert
condition, a throw
or revert
statement, or by attempting for an invalid operation (such as integer overflow during arithmetic operations since Solidity 0.8). If it's the generic message, you'll need to debug the contract variable values, return values of external contracts that it might be calling, etc.