BC5: Ethereum in practice: accounts, transactions, gas and networks
Networks: main, test, local and layer 2
🎯You'll be able to
Choose the right network for each stage of work and connect to it safely.
🏠The everyday picture
A driving school car park, the quiet roads near it, and the highway: you practise in each before the next.
📘What it really is
-
Local practice network: Hardhat's network on your computer (chain ID 31337). Instant blocks, free test ether, resettable. Its test accounts are public.
-
Public test networks: such as Sepolia (chain ID 11155111). Shared, realistic, free test ether from faucets, but no real value.
- Main network: Ethereum mainnet (chain ID 1). Real value; mistakes cost real money.
-
Layer 2 networks: rollups such as Arbitrum, Optimism and Base run transactions off the main chain and post data and proofs back to it, for lower fees. Each has its own chain ID and its own security assumptions.
-
RPC providers: apps reach a network through an RPC address, from your own node or a provider. Providers limit request rates and the block range of some queries.
-
Check the chain ID: an app should confirm which network it's on before sending anything.
📝A worked example
Input: SakhiKosh's app moves from practice to a public test network.
Steps:
- Practice: chain ID 31337 at http://127.0.0.1:8545, with the test accounts
npm run chainprints. - Public test network: a new RPC address, chain ID 11155111, a fresh account funded from a faucet, and its key in
.env. - The app refuses to send if the chain ID doesn't match the one configured.
Expected output: a safe path from practice to a public test network, with no main network step in the course.
🌍Where it's used
- Development: local networks for tests.
- Staging: public test networks.
- Production: main networks or layer 2 networks.
📝Case scenario
A developer's script was meant for a test network, but their RPC setting still pointed at the main network from another project. The script deployed a contract and paid real fees. A chain ID check at the start of the script would have stopped it.
🖱️Try it
Write the chain IDs of the practice network, Sepolia and Ethereum mainnet. Success: 31337, 11155111 and 1.
⚠️Common mistakes
- No chain ID check. Sign: scripts run on the wrong network. Fix: check first and stop if it's wrong.
- Practice keys on public networks. Sign: funds taken from a public test account. Fix: fresh keys outside the practice network.
- Assuming all layer 2 networks are the same. Sign: one set of assumptions. Fix: read each one's documentation.
🛠️For your project
Project 3's test 1 checks the app refuses to carry on when the chain ID isn't the expected one.
✅Quick check
Why check the chain ID before sending?
Show the answer
So a script meant for one network doesn't send on another, such as the main network.
What is a layer 2 network?
Show the answer
A network that runs transactions off the main chain and posts data and proofs back to it, for lower fees.
