This guide requires foundational blockchain knowledge. Ensure you're familiar with:
- Blockchain
- Bitcoin
- Ethereum
- Key differences between Bitcoin and Ethereum
- Ethereum smart contracts
Understanding these concepts will help you grasp the significance of each step.
Prerequisites
We'll use two tools:
geth: A Go-Ethereum client for running Ethereum nodes via terminal.puppeth: Simplifies genesis block configuration for private chains.
While manual JSON configuration is possible, outdated examples often cause errors. puppeth (bundled with geth since v1.6) is recommended.
Installing Geth
Mac users:
brew tap ethereum/ethereum
brew install ethereum Verify with:
geth version Output:
Geth
Version: 1.8.12-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10.3
Operating System: darwin For other OS, refer to go-ethereum GitHub.
Creating Node Directories
Set up folders for each node (e.g., private-chain-node1, private-chain-node2). Use separate terminals to simulate multiple nodes:
cd /Users/AndyWu/Desktop/private-chain-node1 # Terminal 1
cd /Users/AndyWu/Desktop/private-chain-node2 # Terminal 2 Creating Ethereum Wallets for Nodes
Generate wallets for each node:
geth --datadir ./ account new # Terminal 1 & 2 Note the 0x-prefixed wallet addresses—you’ll need them later.
Configuring the Genesis Block with puppeth
Name Your Private Chain:
puppeth > TestChain- Select "Configure new genesis".
Choose Consensus:
- Clique (PoA) for private chains.
- Set Block Time: Default (15 seconds).
- Assign Sealers: Enter wallet addresses from earlier.
- Pre-fund Accounts: Same addresses.
- Set Chain ID: E.g.,
123456. - Export Configuration: Save as
genesis.json.
Applying Configuration to Nodes
Initialize nodes with the genesis file:
geth --datadir private-chain-node1 init genesis.json # Terminal 3
geth --datadir private-chain-node2 init genesis.json Starting the Nodes
Launch each node with unique ports:
geth --datadir ./ --networkid 123456 --port 8000 --nodiscover console # Terminal 1
geth --datadir ./ --networkid 123456 --port 8001 --nodiscover console # Terminal 2 Verify with:
admin.nodeInfo Connecting Nodes
Retrieve
enodefrom Terminal 1:admin.nodeInfo.enodeIn Terminal 2, add the peer:
admin.addPeer("enode://[email protected]:8001")Confirm connection:
net.peerCount // Should return 1 admin.peers // Details of connected peers
👉 Explore advanced node configurations
Common Geth Commands
| Command | Purpose |
|---|---|
personal.newAccount() | Create a new wallet. |
miner.start() | Start mining. |
eth.getBalance(0x...) | Check wallet balance. |
eth.sendTransaction({...}) | Transfer ETH between accounts. |
eth.blockNumber | Latest block number. |
FAQ
Q: Why use PoA over PoW for private chains?
A: PoA restricts block sealing to authorized nodes, ensuring control and efficiency.
Q: How do I fund accounts in the genesis block?
A: Specify wallet addresses during puppeth setup under "pre-funded accounts."
Q: Can I change the miner account later?
A: Yes, use miner.setEtherbase(0x...).
👉 Learn more about Ethereum private chains
Next Up: Deploying smart contracts to your private chain.