How to fork mainnet with your ETH2 node

Doug Crescenzi
Upstate Interactive
2 min readFeb 25, 2021

We have way too much fun building smart contracts on Ethereum…

Over the years we’ve developed dozens of smart contracts for our clients. Many have required us to fork mainnet in order to test. Doing so enables us to simulate having the same state as mainnet on our local development network. We can then interact with deployed protocols and test complex interactions locally.

Up until recently we had been forking mainnet from Infura. Infura is a solid service and we appreciate all that they (and Consensys) do for the ecosystem. However, in using Infura we often encountered rate limits and our tests wouldn’t run as fast as we’d like to see.

To address this we recently began forking mainnet from our ETH2 node. We’re running DAppNode with a Geth client that gives us access to a synchronized ETH1 mainnet.

To fork from our node is super simple (….so long as we don’t forget to VPN into it 😜).

For those using Ganache it’s as easy as:

ganache-cli -f http://geth.dappnode:8545

For Hardhat:

npx hardhat node --fork http://geth.dappnode:8545

Lastly, make sure your config file is using the correct port and network and you’ll be good to go.

If you have any questions or get stuck when trying to fork your own ETH2 node, feel free to reach out: team@upstateinteractive.io.

To stay up-to-date with Upstate Interactive, sign up for our newsletter.

🤖

--

--

Doug Crescenzi
Upstate Interactive

vp, software engineering @ Foundry, previously founding partner at Upstate Interactive (acq'd by Foundry in '22)