Building an Ethereum Private Chain with Geth and Mist Wallet

·

Introduction

Amidst the blockchain revolution, Ethereum stands out as the leading platform for programmable smart contracts. While alternatives like Hyperledger and EOS exist, Ethereum remains the most mature solution. This guide walks you through setting up your own Ethereum private chain using Geth (command-line client) and Mist (visual wallet).


1. Downloading Geth and Mist Clients

Ethereum Client Types

Download Links (Windows)


2. Genesis Block Configuration (genesis.json)

{
  "config": {
    "chainId": 101,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "alloc": {},
  "coinbase": "0x0000000000000000000000000000000000000000",
  "difficulty": "0x400",
  "gasLimit": "0xffffffff",
  "nonce": "0x0000000000000042",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00"
}

Key Parameters

ParameterPurpose
chainIdUnique network ID (avoid 1, the mainnet)
difficultyMining difficulty (lower = easier)
gasLimitMinimum gas consumption per block

3. Initialize the Node

geth --datadir data0 init genesis.json

4. Start the Geth Node

geth --identity "TestNode1" --datadir "data0" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --rpcport "8486" --port "30304" --networkid "29382" console

Command Breakdown

FlagFunctionality
--identityNode name (e.g., "TestNode1")
--rpcapiEnabled APIs (e.g., eth, web3)
--networkidMust match across all private nodes

5. Essential Geth Commands

// Create an account
personal.newAccount("123456");

// List accounts
eth.accounts;

// Unlock an account
personal.unlockAccount(eth.accounts[0], "123456");

// Check balance
eth.getBalance(eth.accounts[0]);

// Start/stop mining
miner.start();
miner.stop();

6. Multi-Node Setup

Add a Second Node

  1. Initialize:

    geth --datadir data1 init genesis.json
  2. Start:

    geth --identity "TestNode2" --datadir "data1" --rpcport "8487" --port "30305" --networkid "29382" console
  3. Connect nodes:

    admin.addPeer("enode://...@[YOUR_IP]:30304");

7. Launch Mist Wallet


8. Deploy Smart Contracts via Mist

Example Contract (Token.sol):

pragma solidity ^0.4.18;
contract Token {
  mapping (address => uint) public balancesOf;
  address public owner;

  function Token() public {
    owner = msg.sender;
    balancesOf[msg.sender] = 10000;
  }
  // ... (additional functions)
}
  1. Deploy via Mist UI.
  2. Mine the transaction (miner.start()).

FAQs

Q: Why use a private chain?
A: For testing smart contracts without real ETH or mainnet fees.

Q: How do I reset the chain?
A: Delete the data0/data1 folders and reinitialize.

Q: Can I sync private chains across machines?
A: Yes—ensure identical genesis.json and networkid.


Conclusion

This setup lays the groundwork for Ethereum development. Future topics include Solidity best practices and advanced contract deployment.

👉 Explore advanced Ethereum tools