What Is Mainnet fork?

A mainnet fork is a local copy of a live blockchain’s state used for development and testing. By forking mainnet, developers get a local EVM environment that mirrors the real chain - including all deployed smart contracts, token balances, and protocol state - without spending real assets or affecting production systems.

Mainnet forks are essential for:

  • Testing smart contract interactions against real protocol deployments (e.g. swapping on Uniswap, borrowing on Aave)

  • Simulating complex DeFi transactions before executing them onchain

  • Debugging failed transactions by replaying them locally

  • Developing trading strategies that interact with live liquidity pools

The most common tool for creating mainnet forks is Anvil, part of the Foundry toolkit for EVM development. Anvil spins up a local JSON-RPC node that fetches and caches state from a remote RPC endpoint. Other tools include Hardhat Network and Ganache (deprecated).

A typical Anvil mainnet fork command:

anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY

This starts a local node at http://localhost:8545 with the full Ethereum mainnet state available for read and write operations.

See also