This comprehensive guide walks you through setting up an Ethereum private test network using Geth, the official Go implementation of the Ethereum protocol. Perfect for developers and enthusiasts looking to experiment with blockchain technology in a controlled environment.
System Requirements
Before beginning, ensure your systems meet these minimum specifications:
- Operating System: Ubuntu (recommended)
- Memory: 8GB RAM
- Processor: Intel Xeon E5-2620 or equivalent
Installing Geth
Geth is the command-line interface for running a full Ethereum node. Install it with these commands:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereumCreating a Private Test Network
A private Ethereum network allows you to:
- Pre-allocate Ether to test accounts
- Adjust mining difficulty for faster block generation
- Test smart contracts without using real cryptocurrency
Key Configuration Steps
- Custom Genesis Block Creation
- Specifying Data Storage Location
- Setting Network ID
- Disabling Node Discovery (Recommended)
Configuring the Genesis Block
The genesis block is the first block in your blockchain. Create a CustomGenesis.json file with these essential parameters:
{
"config": {
"chainId": 3131,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "200000000",
"gasLimit": "2100000",
"alloc": {
"7df9a875a174b3bc565e6424a0050ebc1b2d1d82": {
"balance": "300"
},
"f41c74c9ae680c1aa78f42e5647a62f353b7bdde": {
"balance": "400"
}
}
}Critical Parameters Explained:
chainId: Prevents replay attacksdifficulty: Controls mining complexitygasLimit: Sets per-block gas expenditure capalloc: Pre-funds specified accounts
Initializing the Genesis Block
Run this command to initialize your blockchain:
geth --datadir /path/to/data init /path/to/CustomGenesis.jsonLaunching Your Private Network
Start your node with these recommended parameters:
geth --identity "ETH-MainNode" --rpc --rpcport "6060" --rpccorsdomain "*" \
--datadir "/path/to/chaindata" --port "30303" --nodiscover --maxpeers 5 \
--rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" \
--networkid 3131 consoleConnecting Nodes
Get node information from the first node:
> admin.nodeInfo- Note the
enodeaddress On the second node, add the peer:
> admin.addPeer("enode://...@[IP_ADDRESS]:30303")Verify connection:
> net.peerCount
Testing Your Private Network
Account Creation
Create accounts on both nodes:
> personal.newAccount()Mining Ether
Start mining to generate test Ether:
> miner.setEtherbase("0xYourAddress")
> miner.start(1)Executing Transactions
Unlock your account:
> personal.unlockAccount("0xYourAddress")Send a test transaction:
> eth.sendTransaction({ from: "0xSenderAddress", to: "0xReceiverAddress", value: web3.toWei(10, "ether") })Verify balances:
> eth.getBalance("0xReceiverAddress")
FAQ Section
How do I know my private network is working properly?
Verify by checking:
- Peer connections (
net.peerCount) - Block generation (
eth.blockNumber) - Successful transactions (
eth.getTransactionReceipt(txHash))
What's the difference between chainId and networkId?
chainId: Used for transaction signing (prevent replay attacks)networkId: Identifies the network for peer-to-peer communication
Can I connect more than two nodes?
Absolutely! Simply repeat the node connection process for additional nodes using the same genesis block and network ID.
๐ Learn more about advanced Ethereum development
Conclusion
By following this guide, you've successfully created a functional Ethereum private test network. This environment is perfect for:
- Smart contract development
- DApp testing
- Blockchain protocol experimentation
Remember to stop mining when not testing to conserve resources:
> miner.stop()For further exploration of Ethereum development, check out these resources:
๐ Official Ethereum documentation
๐ Smart contract development tutorials