Skip to main content

Overview

Chain forking creates a local copy of a live blockchain network. Your local environment gets the complete state of the target network — all contracts, all balances, all storage — at a specific block. This lets you:
  • Test against real DeFi protocols — Interact with Uniswap, Aave, Compound, etc. locally
  • Reproduce mainnet bugs — Fork at the block before a bug and replay the transaction
  • Test token integrations — Use real USDC, WETH, DAI balances in your tests
  • Simulate governance — Impersonate any address and execute transactions

Quick Start

# Start your environment
dokrypt up

# Fork Ethereum mainnet at the latest block
dokrypt fork mainnet

# Fork at a specific block
dokrypt fork mainnet --block 18500000

# Fork Polygon
dokrypt fork polygon

Supported Networks

NetworkAliasesChain IDPublic RPC
Ethereummainnet, ethereum1https://eth.llamarpc.com
Sepoliasepolia11155111https://rpc.sepolia.org
Goerligoerli5https://rpc.ankr.com/eth_goerli
Polygonpolygon137https://polygon-rpc.com
Arbitrumarbitrum42161https://arb1.arbitrum.io/rpc
Optimismoptimism10https://mainnet.optimism.io
Basebase8453https://mainnet.base.org
BSCbsc56https://bsc-dataseed.binance.org
Avalancheavalanche43114https://api.avax.network/ext/bc/C/rpc

Using Custom RPC URLs

For faster forks or private access, use your own RPC URL:
dokrypt fork --url https://eth-mainnet.alchemyapi.io/v2/YOUR_KEY
Or with the --fork flag on dokrypt up:
dokrypt up --fork mainnet
dokrypt up --fork polygon --fork-block 50000000

Fork on Startup via Config

You can configure forking directly in dokrypt.yaml:
chains:
  ethereum:
    engine: anvil
    chain_id: 31337
    fork:
      network: mainnet
      block_number: 18500000

Use Cases

Test Against Uniswap

# Fork mainnet
dokrypt fork mainnet

# Your local chain now has all of Uniswap's contracts
# Interact with the Router at 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D

Impersonate a Whale

# Fork mainnet
dokrypt fork mainnet

# Impersonate a USDC whale
dokrypt accounts impersonate 0x47ac0Fb4F2D84898e4D9E7b4DaB3C24507a6D503

# Now you can send USDC from this address without the private key

Reproduce a Bug

# Fork at the block just before the bug
dokrypt fork mainnet --block 17999999

# Impersonate the affected account
dokrypt accounts impersonate 0xAffectedAddress...

# Replay or investigate

Multi-chain Fork

If your dokrypt.yaml has multiple chains, specify which one to fork:
dokrypt fork mainnet --chain l1
dokrypt fork polygon --chain l2

How It Works

  1. Resolution — The network name is resolved to an RPC URL
  2. Resetanvil_reset (or hardhat_reset) is called with the fork configuration
  3. Wait — Dokrypt waits up to 120 seconds for the fork to complete
  4. Funding — Test accounts are funded with 10,000 ETH each
  5. Ready — The local chain is now a fork of the target network
Forking from public RPCs can be slow. For production testing, use a dedicated RPC provider (Alchemy, Infura, QuickNode) for much faster fork times.