Test Against Real Mainnet State With Hardhat Forking Without Spending Gas
Use Hardhat Network with mainnet forking to run integration tests against a pinned replica of real on-chain state, with impersonation and time controls for safe simulation.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Use Hardhat Network with mainnet forking to run integration tests against a pinned replica of real on-chain state, with impersonation and time controls for safe simulation.
Hardhat mainnet forking lets you run integration tests against real deployed contracts and balances locally. Learn the setup, a worked impersonation example, and the RPC trade-offs.
Fork mainnet at a fixed block and cache state locally to get deterministic integration tests against real deployed contracts without spending gas.
Learn how to use Hardhat Mainnet Forking to simulate production environments, pin block numbers for deterministic testing, and impersonate live accounts for administrative testing.
Hardhat Mainnet Forking lets you test against live Ethereum state at a pinned block. Configure forking in hardhat.config.js, impersonate whales for write access, and avoid RPC rate limits with caching and archive endpoints.
Hardhat's mainnet forking lets you test against live protocol state locally. This post covers lazy-loading state, account impersonation, a worked Uniswap V3 example, and memory trade-offs.