Lesson 3 of 3 Ethereum Nodes and Clients

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.

Select all that apply

What a development node gives you

Exam skills 7.3.1

Identify the benefits of a local development node over a public network.

Log in to try this activity Interactive activities are free with an account.

Hardhat node

In a Hardhat project, the following command starts Hardhat Network as a standalone JSON-RPC server.

npx hardhat node

It 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.

Hardhat node
Comes withHardhat (Node.js)
Start commandnpx hardhat node
Accounts20 funded accounts
Chain ID31337
StrengthIntegrated with Hardhat tests, stack traces, console.log
Anvil
Comes withFoundry (Rust)
Start commandanvil
Accounts10 funded accounts
Chain ID31337
StrengthVery fast, rich cheatcodes
Geth --dev
Comes withGeth, a production execution client
Start commandgeth --dev --http
AccountsOne pre-funded developer account
Chain ID1337
StrengthReal client behaviour

Ganache, 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).

Match the pairs

Development nodes

Exam skills 7.3.1

Match each development node with a description of it.

Log in to try this activity Interactive activities are free with an account.

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.

MethodEffect
evm_mineMine a block immediately
evm_increaseTimeMove the chain's clock forward by a number of seconds
evm_snapshot / evm_revertSave the chain state and later return to it
hardhat_setBalanceSet any account's ether balance
hardhat_impersonateAccountSend transactions as any address without its key
Match the pairs

Development RPC methods

Exam skills 7.3.2

Match each development RPC method with what a test would use it for.

Log in to try this activity Interactive activities are free with an account.

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 23000000

Pinning 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.

Scenario questions

Forking

Exam skills 7.3.2

Decide when and how to fork a live network for testing.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Worked example

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.

Check yourself

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.