2

Miners will include the transactions into block and those will change the state of a lot of variables including the balances of accounts.

I wanted to do it in my local node before sending transaction! ( not the ganache node for testing.) I want to simulate in mainnet state.

Could you give any advice for this?

3 Answers 3

2

You can simply fork mainnet locally. Modern tooling allows you to do this easily, check for example https://hardhat.org/hardhat-network/guides/mainnet-forking .

After you have forked it, you can do whatever you want with it, with no cost (since it's your local blockchain at that point). You even have access to cheat and use functionality which wouldn't be possible in real networks (such as impersonating an account).

Another option is to run the transaction to the live mainnet, but not as a real transaction but as a local static call, which is free and doesn't alter the blockchain state. You can read more here: https://docs.ethers.io/v5/single-page/#/v5/api/contract/contract/-%23-contract-callStatic

0

the closest thing is one of the Ethereum test networks like rinkeby or goerli. They work the same as the mainnet. You can deploy to a testnet using a service like alchemy.

If that's not close enough to the real thing for you're looking at forking the mainnet.

1
  • certificate is missing on your website, antivirus does not like it : "invalid certificate name"
    – Heetola
    Nov 29, 2023 at 19:05
0

You can simulate Ethereum transactions on the mainnet with Pelta Shield.

This tool allows you to see the usual tx info (such as what you would see on Etherscan) before the transaction actually gets included in a block.

It can therefore be particularly useful for testing and debugging purposes, as it allows you to see how the transaction would affect the state of the Ethereum blockchain without the need to wait for it to be mined and included in a block.

In fact you can even abort the simulated transactions if you don't like the result of it, and you will not pay any gas.

Note that the results of the simulation will only be accurate as long as the transaction doesn't depend too much on the live state of the Ethereum blockchain.

If the state of the blockchain changes between the simulation and the actual execution, the simulation may not accurately reflect the result of the transaction.

DISCLAIMER: I should mention that I am the founder of Pelta.tech, the startup that developed Pelta Shield, so I'm definitely biased in my recommendation.

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.