trufflesuite / ganache-cli-archive

Fast Ethereum RPC client for testing and development. See https://github.com/trufflesuite/ganache for current development.
https://www.trufflesuite.com/ganache
MIT License
3.36k stars 696 forks source link

Ganache-cli Fork will not last. Subsequent transactions fail with nonce error and / or out of gas error #812

Closed Madeindreams closed 3 years ago

Madeindreams commented 3 years ago

https://gitter.im/ConsenSys/truffle?at=5ffa7e309632f63d87099576

I have a local Geth node and I fork the mainnet on it using Ganache-cli like so

ganache-cli -f http://127.0.0.1:9545 -m "clutch captain shoe salt awake harvest setup primary inmate ugly among become" -i 1 -u 0xC28197af6D4F8C6dE7b79e6c52Af0176fB2961f7

I use the first provided key to import the first account that ganache returns in Metamask.

Using Remix I am able to deploy a contract. After the deployment, if I try to interact with the contract, it will revert with a nonce error. But prior to that, Remix is warning me that it will potentially fail with this message;

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { "message": "VM Exception while processing transaction: revert", "code": -32000, "data": { "stack": "c: VM Exception while processing transaction: revert\n at Function.c.fromResults (C:\Users\iando\AppData\Roaming\nvm\v15.5.0\node_modules\ganache-cli\build\ganache-core.node.cli.js:4:194749)\n at e.exports (C:\Users\iando\AppData\Roaming\nvm\v15.5.0\node_modules\ganache-cli\build\ganache-core.node.cli.js:55:2098470)", "name": "c" } }

"the tx doesn't have the correct nonce. account has nonce of: 0 tx has nonce of: 1"

So I think my first contract deployment in remix was counted has 1 transaction in metamask. But I guess Ganache return none.

I also tryed to send Ether from Metamask and got an out of gas error. This should be my second transaction to get my contract to work. I don't get an error in Remix but in the advance settings of Metamask i can see this error message;

EthQuery - RPC Error - Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction: out of gas","code":-32000,"data":{"0xcc6c10b90bb7087d9aa185121fa602bc907d6f6abecb0e666899eb60cf31fd46":{"error":"out of gas","program_counter":0,"return":"0x"},"stack":"c: VM Exception while processing transaction: out of gas\n at Function.c.fromResults (C:\Users\iando\AppData\Roaming\nvm\v15.5.0\node_modules\ganache-cli\build\ganache-core.node.cli.js:4:194749)\n at A.w.processBlock (C:\Users\iando\AppData\Roaming\nvm\v15.5.0\node_modules\ganache-cli\build\ganache-core.node.cli.js:42:50247)\n at runMicrotasks ()\n at processTicksAndRejections (node:internal/process/task_queues:93:5)","name":"c"}}}}'

When i click on deploy in Remix. I can see that it's trying to call for estimateGas in the Geth console. And this is when it raise a warning. Also a Gas issue when trying to send ether.

Your Environment

Ganache CLI v6.11.1-beta.1 (ganache-core: 2.13.0-beta.0) Remix 0.10.7 Node v15.5.0 Windows 10 x64 WSL2 Ubuntu

Chriscorp commented 3 years ago

Good morning @Madeindreams ... I'm having the same issues too even using metamask and after turning ganache to a local blockchain: EthQuery - RPC Error - Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction: out of gas","code":-32000,"data":{"0x7...40":{"error":"out of gas","program_counter":0,"return":"0x"},"stack":"RuntimeError: VM Exception while processing transaction: out of gas\n at Function.RuntimeError.fromResults

My environment: Metamask 2.0.0 Node 14.16.0 windows 10 x64 Truffle 5.2.3 web3.js 1.2.9

Madeindreams commented 3 years ago

Hey Chriscorp! The error messages in the case of a fork of the mainnet are often as helpfull as just saying ERROR.

It could be an error in your code or a missing view declaration. It could be anything.

So unless you can get a more explicit error it's really hard to know what is causing this error.

Break your code down in smaller part. It's easyer to debug one thing than 10.