0

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?

pdmoerman
  • 83
  • 4
  • 10

1 Answers1

0

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.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • When commenting out the estimate gas, the subsequent sendSignedTransaction reverts. So that solves the big mystery of the internal error for me. Thanks! – pdmoerman May 19 '21 at 13:52
  • I know why that particular transaction is reverting, however, another call that I expect to work reverts, and web3.eth.handleRevert doesn't work for sendSignedTransaction. Do you know how I can get the revert reason from a signed transaction? – pdmoerman May 19 '21 at 13:53
  • You should be able to get the revert reason (if there's any) from the `exception.data[txHash].reason`. See my [other answer](https://stackoverflow.com/a/66884487/1693192) for code example. – Petr Hejda May 19 '21 at 14:58
  • When attempting that, I get the following error: Unhandled rejection at Promise: Promise { TypeError: Cannot convert undefined or null to object at Function.keys () The returned error seems to be a string not an object. It has an object embedded in it, but I've not found a way to access it. – pdmoerman May 19 '21 at 15:16
  • It seems you're not handling the promise correctly, but I'm not able to debug it without code example, and comments are not very good place for this. Please ask a separate question with the code example (it's a general JS code issue, not related to web3 or smart contracts). – Petr Hejda May 19 '21 at 15:19