Simulated Networks by EDR
Hardhat can simulate Ethereum and Layer 2 blockchains locally, a feature powered by Nomic Foundation’s Ethereum Development Runtime, or EDR.
This document explains how network simulations work. For a full list of features, check out the reference documentation.
What are simulated networks?
Section titled “What are simulated networks?”Simulated networks are in-process blockchains that run entirely on your local machine.
Unlike connecting to a remote node through JSON-RPC, simulated networks give you complete control over the blockchain state, block production, and transaction execution. They’re faster and free to use.
The only difference between a blockchain simulated by EDR and a production one is that EDR requires no consensus mechanism or peer-to-peer network, as it’s run by a single process each time.
When you call await network.connect() with a Network Config of type edr-simulated, Hardhat creates a new, independent blockchain simulation. Each simulation is isolated, so you can create multiple simulations simultaneously without them interfering with each other.
How to use simulated networks
Section titled “How to use simulated networks”You can use simulated networks in two ways:
In-process simulations
Section titled “In-process simulations”When you run your tests or scripts, Hardhat automatically creates an in-process simulated network. For example:
import { network } from "hardhat";
const connection = await network.connect();This creates a new blockchain simulation based on the Network Config specified in your configuration file or via the --network flag.
Standalone node
Section titled “Standalone node”You can also run a simulated network as a standalone process that exposes a JSON-RPC interface over HTTP:
npx hardhat nodepnpm hardhat nodeyarn hardhat nodeThis starts a local node at http://127.0.0.1:8545 that you can connect to with wallets, applications, Hardhat, or other tools.