Metamask-extension: Failed gas estimation causes JSON-RPC error -32603

Created on 17 Oct 2019  Â·  17Comments  Â·  Source: MetaMask/metamask-extension

To Reproduce

I'm not 100% sure what the precise cause of this bug is, but there exists a combination of 1) Solidity code 2) Ganache running locally 3) MetaMask v7.2.3 where a contract function invocation fails as such:

inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: "Internal JSON-RPC error.", data: {…}, stack: "Error: "message" must be a nonempty string.↵    at…eogaeaoehlefnkodbefgpgknn/background.js:1:1207412"}

The fix is to specify the gasLimit in the code. As such, I believe that this is either a bug in Ganache's gas estimation mechanism, or the way that MetaMask makes gas estimation requests.

I hope this helps anyone who's searching for a solution. In the meantime, I'll work on a simple example to reproduce this bug.

L31-gas

All 17 comments

I got this problem too. My method is just a simple getState from the smart contract and now they threw an error, I tried to add gasLimit but clearly this method does not need any gasLimit. This happen after the MetaMask get updated.

I have the same problem here with Metamask 7.3.1. Can you suggest a version where this does not cause a problem? Thanks in Advance

Same issue. Trying to work with Validator Sets on a parity poa client. Using remix ide so no option to set gasLimit in code. Metamask resets gasLimit when I try setting it to zero.

This issue isn't about view functions, by the way.

I am also seeing this issue, triggering on MM 7.3.1 in both Remix and Ganache on networks. Looks like its having connectivity issues to ganache when using MM atm, not sure if this is related

I have the same issue. Setting gasLimit didn't help. No problems calling that particular function via truffle console though.
Thanks for posting this issue @weijiekoh! Any progress on the simple example to reproduce the bug?

I'm having the same problem, it seems in my case, when calling a public function: myContract.methods.someMethod().call() I needed to add the {from: <myAddress>} in order of it to working inside the .call().

This works:
myContract.methods.someMethod().call({from: <myAddress>})

The error message could be a bit more informative however.... :-)

I haven't gotten around to reproducing this bug, but I suspect it has to do with a situation where contract A calls a function in contract B, and Ganache can't estimate the gas needed.

To reiterate - this is not about view functions. It has to do with send functions (which you pay gas to trigger).

In this case we were receiving this issue due to running our test cases against an older version of our smart contract. Deleting our build folder and completely restarting our Ganache workspace made certain that our most up to date smart contract was actually the one being utilized.

I ran into this issue as well when attempting to send transactions with ethers.js to a local ganache blockchain (some fraction of attempted transactions fail). In case anyone else is experiencing the same, using overrides to manually set the gas cost seems to fix the issue. Example:

async move(args: MoveArgs): Promise<providers.TransactionReceipt> {
    let overrides: any = {
      gasLimit: 1000000
    };
    const tx: providers.TransactionResponse = await this.contract.move(...args, overrides);
    return tx.wait();
  }

In my case, the error is thrown out here
https://github.com/MetaMask/eth-json-rpc-errors/blob/226134b0a9c3aebe3c2fa1112d8ad54ef018c48f/src/classes.js#L22
The version of eth-json-rpc-errors is 1.1.0.
It's called here
https://github.com/MetaMask/eth-json-rpc-middleware/blob/5bf9eb4fc7924c65636a3cb5d19648489c8aed04/fetch.js#L79
Which is eth-json-rpc-middleware version 4.2.0.
The body.error is a {code: Number, message: String, .....}.

Seems it's fixed by below commit.
https://github.com/MetaMask/eth-json-rpc-middleware/commit/212c269

This only relevant to the message string error. Not the gas estimation error.

Same issue calling function with gas price 0 on my private chain.
version 7.7.1

I am also having this result and can reproduce on 2 machines.

I had the issue, putting gasLimit to 30000 solved it.
Don't know why

I had the same issue, it popped out of nowhere.
Setting up the gasLimit did not do anything, I suspected a nonce problem since everything worked on Rinkeby.
So resetting the account fixed it, but of course I lost all my transactions history 😓

Metamask 7.7.2
Web3.js 1.2.4
Ganache CLI v6.7.0 (ganache-core: 2.8.0)
Solc 0.5.11+commit.c082d0b4.Emscripten.clang

Setting gasLimit does not work.
so how to fix it? What do you mean by resetting account?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BMillman19 picture BMillman19  Â·  3Comments

hellobart picture hellobart  Â·  3Comments

1blockologist picture 1blockologist  Â·  3Comments

aecc picture aecc  Â·  3Comments

aakilfernandes picture aakilfernandes  Â·  3Comments