I am running my own local Geth node and my main objective is to simulate some transactions and see how does the state of the blockchain change from the current one. For instance if I simulate a tx where A sends 3Eth to B, after the simulation I would like to see that in a new simulated block where only that tx was mined, addresses A and B would change. Then I could myself query from this new state the balances using web3.

My questions are:

  1. As I said I'm currently running my own local node. If I simulate a tx and thus create a new state of the blockchain, how would that interfere with my REAL node? Would it get de-sync? Would Geth save a parallel temporary (simulated) state so I can interact with it while the original one keeps getting sync? Would it only save as a new temporary state the addresses that changed?
  2. From what I've read around the way to go is to use geth's method eth_call. However I'm not sure if this is only for calls, or also for state changing transactions (what I'm actually interested in)?
  3. Assuming eth_call is the correct method to call, how could I see what addresses' state changed (not necessarily only eth balances, could also be storage change, etc) inmediately after simulating the transaction?
  4. I know that Truffle has an option to --unlock addresses with permission modifiers so you can simulate transactions calling those addresses anyway, does Geth provide something similar?

I know these are quite some questions, thanks!

3 Answers 3

  1. There is no simulation in Geth, all transactions go for real. It is just that locally you have your own chain, all transfers are executed on your chain and nobody sees them. You can not connect to Ethereum Main Net because the hash of your block 0 (genesis) is different from the Main Net, so you will never interfere with the Main Net. Simply, nobody will connect to your node.
  2. Call() uses the state of last block and doesn't store any data in the StateDB because it can not. You need to enable mining and send a transaction so blocks could be generated and consensus algorithm triggered. Call just calls the EVM and executs the code and returns the output from the contract.
  3. If you want real state change with MainNet data you need to have a look at the State Transition tools located here: https://github.com/ethereum/go-ethereum/tree/master/cmd/evm , they mean exactly for the purpose of simulating real exeuction but you need to assemble each test case manually
  4. Neither Truffle nor any other tools will be able to do what you want, to simulate a transaction with saved State you need to modify Geth to break all rules and store an invalid State by creating the transaction that you want, but after that you won't be able to sync with other nodes as the State Root hash of your fake block will be different
  • Hi Nulik, thanks for your comment, I have a couple of questions. In point 1, does that mean that I would need 2 separate nodes (one for mainnet and one for 'simulating') and can't be done with just 1 node? And more importantly, about point 3. I've been reading a bit more and it seems that what I need is something called EVM tracing, specifically debug.traceTransaction(tx) (geth.ethereum.org/docs/rpc/ns-debug#debug_tracetransaction). Would you be able to shed some light on this maybe? I want to simulate mempool pending txs, not already mined txs in the past, by the way. Thanks again!
    – Hiperfly
    Commented Jul 28, 2021 at 12:35
  • no, it cant be 1 node because you have 2 different blockchains, one is MainNet, another is your own, local
    – Nulik
    Commented Jul 28, 2021 at 20:49
  • debug.traceTransaction() is for replicating existing transaction with all opcodes executed. It is not simulation.
    – Nulik
    Commented Jul 28, 2021 at 20:50
  • 1
    if you need this for trading , then check Flashbots website, they have a geth node that does simulation , just like you want it, but this is for frontrunning
    – Nulik
    Commented Jul 28, 2021 at 20:51
  • I just checked the Flashbot's MEV-Geth but is not vervose enough for what I need it, since it only outputs tx hashes mapped to values and it's leaving a lot of info aside (docs.flashbots.net/flashbots-auction/miners/mev-geth-spec/…). I've found something that might work and that is OpenEthereum's tracing, more vervose (without being as low level as default Geth's) and easy to parse. I have one last question below for you (not enough characters here).
    – Hiperfly
    Commented Jul 29, 2021 at 7:54
  1. It would create a fork, which is soon to be rejected by the rest of the nodes, thus you get desynced, yes.
  2. No, it's only for reading, for writing you need eth_sendTransaction. More on this here: https://eth.wiki/json-rpc/API
  3. I'm not sure how much debugging Geth does provide but this might help: https://github.com/trufflesuite/truffle-plugin-debugger. Simply configure Truffle to connect your Geth node.
  4. I don't know about this.
  • Thanks for your answer. So number 1 would mean that if I'm using my local node for other projects, I would actually need to set up a second node just for simulating these transactions correct? About the debugger not sure if it's what I need, I would like to do it in an automated kind of way since I'd like to simulate many transactions. I've been researching a bit more and it seems what I actually need is called EVM Tracing, available in Geth but still looking more info about it if you could help. Thanks again!
    – Hiperfly
    Commented Jul 28, 2021 at 10:27
  • 1
    Indeed, you need different nodes for local development and mainnet simulations. I not much experienced on Geth unfortunately, can't say about tracing. Good luck!
    – ferit
    Commented Jul 28, 2021 at 10:31

You may want to use Hardhat network forking - see https://hardhat.org/hardhat-network/docs/guides/forking-other-networks

This allows you to "branch off" your local network at desired block height and execute your custom transactions sequentially without interfering with the actual chain. By default, the fork will auto-mine a block for each tx sent, but you can control that (eg. time-based blocks or trigger new block manually).

Another great feature is that you can impersonate any account (without possessing the private key) - so you don't have to come up with crazy ideas to get certain tokens (like having to trade on Uniswap or playing with state overrides)

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.