Running a Local Development Node
Development nodes give every developer a private blockchain that starts in seconds. This lesson shows how to run and configure Hardhat's node, compares it with Anvil and Geth's developer mode, and explains forking, mining modes and the safety rules for development accounts.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the defaults of a Hardhat node.
- Compare Hardhat Network, Anvil and Geth developer mode.
- Explain automine, interval mining and development RPC methods.
- Explain how forking works and when to use it.
- Identify the safety rules for development accounts and RPC exposure.
Why a local node
Developing directly against a public network is slow and awkward: every transaction waits for a block, needs faucet ether and leaves permanent records. A local development node simulates Ethereum on the developer's machine. It mines instantly, provides accounts pre-funded with large balances, can be reset at will and offers extra RPC methods to control time and state. Development nodes simulate consensus internally, so they need no consensus client.
What a development node gives you
Hardhat node
In a Hardhat project, the following command starts Hardhat Network as a standalone JSON-RPC server.
npx hardhat nodeIt listens on http://127.0.0.1:8545 for both HTTP and WebSocket connections, uses chain ID 31337, and prints 20 accounts, each with 10,000 ETH and its private key. The accounts are derived from a well-known mnemonic, so they are identical on every machine: the first account is always 0xf39F...2266, and the first contract it deploys is always at 0x5FbDB2315678afecb367f032d93F642f64180aa3. Scripts, wallets and Hardhat tasks run with --network localhost connect to this node.
Well-known keys
The development accounts' private keys are published in documentation and printed by every copy of Hardhat. Anything sent to these addresses on a real network is taken immediately by bots. Use them only on local chains.
Hardhat tests do not need this server: npx hardhat test creates a fresh in-process network for each run.
Anvil, Geth developer mode and Ganache
The following comparison sets out the main alternatives.
npx hardhat nodeanvilgeth --dev --httpGanache, with its desktop interface and command-line version, was the standard development node in 2018-era material and in the Truffle Suite. ConsenSys sunset it in 2023. Questions about Ganache translate directly to Hardhat Network or Anvil: a local chain with pre-funded accounts on port 8545 (Ganache's desktop app used 7545).
Development nodes
Mining modes and development RPC methods
By default, development nodes use automine: each transaction is mined in its own block as soon as it arrives. Interval mining produces blocks on a timer instead, which reproduces pending transactions and block timing for front-end testing. Development nodes also accept extra JSON-RPC methods, listed below.
| Method | Effect |
|---|---|
| evm_mine | Mine a block immediately |
| evm_increaseTime | Move the chain's clock forward by a number of seconds |
| evm_snapshot / evm_revert | Save the chain state and later return to it |
| hardhat_setBalance | Set any account's ether balance |
| hardhat_impersonateAccount | Send transactions as any address without its key |
Development RPC methods
Forking a live network
Forking starts a local chain that copies the state of a live network on demand. Contracts and balances are fetched from the given RPC endpoint the first time they are read, and all new transactions stay local.
npx hardhat node --fork https://eth-mainnet.example/v2/API_KEY --fork-block-number 23000000Pinning a block number makes results reproducible and lets the node cache data. Forking is the standard way to test integrations with deployed protocols, such as swapping on a real decentralised exchange, without spending real ether. Anvil uses anvil --fork-url for the same purpose.
Forking
The node another developer can reach
To share a test chain, a developer starts a development node bound to 0.0.0.0 on a cloud virtual machine with port 8545 open to the internet. What is the risk?
The node's accounts are unlocked and their keys are public, and the RPC server accepts transactions from anyone. Strangers can use it freely, and if any real value or real key is ever involved, it can be stolen. Development nodes should listen on 127.0.0.1; to share an environment, use a public testnet or put the node behind authentication on a private network.
Testing a deadline
A crowdfunding contract allows refunds only after a 30-day deadline. How can a developer test the refund path on a local node without waiting 30 days?
Call evm_increaseTime with 30 × 24 × 3,600 = 2,592,000 seconds and then evm_mine so that a new block carries the later timestamp. In Hardhat tests, the network helper time.increase(2592000) does both. The test can then check that refunds succeed after the deadline and revert before it.
What chain ID, address and funded accounts does npx hardhat node use by default?
Show answer
Chain ID 31337, JSON-RPC at http://127.0.0.1:8545 (HTTP and WebSocket), and 20 accounts with 10,000 ETH each whose private keys are publicly known.
Exam Tips
Remember for the exam
- npx hardhat node: 127.0.0.1:8545, chain ID 31337, 20 accounts with 10,000 ETH each.
- Development keys are public; never use them on live networks.
- Automine is the default; evm_increaseTime and evm_mine control time.
- Forking copies live state locally; pin a block number for reproducibility.
- Ganache and Truffle are retired; Hardhat Network and Anvil replace them.