Establishing an Ethereum Private Chain (Part 1): Node Deployment

·

This guide requires foundational blockchain knowledge. Ensure you're familiar with:

Understanding these concepts will help you grasp the significance of each step.


Prerequisites

We'll use two tools:

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

  1. Name Your Private Chain:

    puppeth  
    > TestChain  
  2. Select "Configure new genesis".
  3. Choose Consensus:

    • Clique (PoA) for private chains.
  4. Set Block Time: Default (15 seconds).
  5. Assign Sealers: Enter wallet addresses from earlier.
  6. Pre-fund Accounts: Same addresses.
  7. Set Chain ID: E.g., 123456.
  8. 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

  1. Retrieve enode from Terminal 1:

    admin.nodeInfo.enode  
  2. In Terminal 2, add the peer:

    admin.addPeer("enode://[email protected]:8001")  
  3. Confirm connection:

    net.peerCount  // Should return 1  
    admin.peers    // Details of connected peers  

👉 Explore advanced node configurations


Common Geth Commands

CommandPurpose
personal.newAccount()Create a new wallet.
miner.start()Start mining.
eth.getBalance(0x...)Check wallet balance.
eth.sendTransaction({...})Transfer ETH between accounts.
eth.blockNumberLatest 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.