Ethereum Private Chain Setup Guide

ยท

Introduction to Ethereum Private Chains

Setting up a private Ethereum blockchain allows developers and organizations to create their own blockchain networks for testing, development, or specific business applications. This comprehensive guide covers private chain setup on both Ubuntu and Windows platforms, including wallet deployment and smart contract implementation.

Ubuntu Environment Setup

Basic Environment Configuration

Command Line Installation

  1. Open terminal and execute these commands sequentially:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get update
sudo apt-get install Ethereum

Source Code Compilation (Ubuntu/Mac)

cd go-ethereum
make geth

Environment Variables Configuration

Add Geth to your environment variables:

vim ~/.bashrc

Add these lines to the file:

export GETH="$GOPATH/src/github.com/ethereum/go-ethereum/build"
export PATH="$PATH:$GETH/bin"

Activate the configuration:

source ~/.bashrc

Verify installation by running:

geth -h

Geth Installation and Private Chain Setup

  1. Create a new account:
  2. Edit genesis.json file (sample configuration below)
  3. Initialize private chain:
geth --datadir data --networkid 20140628 --rpc --rpccorsdomain "*" init ./genesis.json

Key parameters:

  1. Start private chain client:
geth --datadir data --networkid 20140628 --rpc --rpccorsdomain "*" --nodiscover --port 16333 --rpcport 8546 console

For additional nodes, use different port numbers.

Mining Operations

  1. Create a new account with password protection:
personal.newAccount("3zzz")
  1. Check account balance:
eth.getBalance("account_address")
  1. Set mining account:
miner.setEtherbase("account_address")
  1. Start mining (single thread):
miner.start(1)
  1. Stop mining:
miner.stop()

Transactions and Ether Conversion

Ethereum units conversion:

web3.fromWei(10000000000000000, "ether") // Returns "0.01"
web3.toWei(1) // Returns "1000000000000000000"

Send transaction between accounts:

web3.eth.sendTransaction({from:web3.eth.accounts[1], to: web3.eth.accounts[2], value: web3.toWei(1, "ether")})

๐Ÿ‘‰ Learn more about Ethereum transactions

Windows Platform Setup

Environment Preparation

  1. Install Ethereum-Wallet:

    • Create dedicated directory (e.g., D:\Eth)
    • Extract Ethereum-Wallet package
  2. Install Geth:

    • Download from official repository
    • Install in dedicated directory
    • Create privatechain folder for blockchain data

Private Chain Configuration

  1. Create genesis.json file with custom configuration:
{
  "nonce": "0x0000000000000042",
  "difficulty": "0x40000",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
  "gasLimit": "0xffffffff",
  "alloc": {
    "3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
      "balance": "1337000000000000000000"
    },
    "17961d633bcf20a7b029a7d94b7df4da2ec5427f": {
      "balance": "229427000000000000000"
    }
  },
  "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  }
}
  1. Initialize genesis block:
geth -datadir "%cd%\\privatechain\\node1" init genesis.json
  1. Start private chain node:
geth --targetgaslimit 4294967295 --rpc --rpcport "8101" --port "30301" --rpcapi "eth,web3,personal" --networkid 2020 --identity 2020 --nodiscover --maxpeers 5 --datadir "%cd%\\privatechain\\node1" --unlock 0 --rpccorsdomain "*" console

Key parameters:

Wallet Operations

  1. Account management commands:
// Create new account
personal.newAccount()

// View accounts
eth.accounts

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

// Unlock account
personal.unlockAccount(eth.accounts[0])
  1. Mining operations:
// Start mining (single thread)
miner.start(1)

// Stop mining
miner.stop()

๐Ÿ‘‰ Explore Ethereum wallet features

Smart Contract Implementation

Contract Deployment

Sample token contract:

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;
    }

    function transfer(address _to, uint _value) public {
        require(balancesOf[msg.sender] > _value);
        require(balancesOf[_to] + _value > balancesOf[_to]);
        balancesOf[msg.sender] -= _value;
        balancesOf[_to] += _value;
    }

    function mint(uint _amount) public {
        balancesOf[owner] += _amount;
    }
}

Contract Interaction

  1. Deploy contract through wallet interface
  2. Activate contract by mining:
miner.start(1)
  1. Interact with contract methods:
// Transfer tokens
contractInstance.transfer.sendTransaction(receiverAddress, amount, {from: senderAddress})

FAQ Section

Q: Why is my transaction not going through?

A: Transactions require miner confirmation. Ensure you have mining active (miner.start(1)) for transaction processing.

Q: How do I convert between Ether and Wei?

A: Use the conversion functions:

web3.fromWei(amount, "ether") // Wei to Ether
web3.toWei(amount, "ether") // Ether to Wei

Q: What's the difference between mainnet and private chain?

A: Mainnet is the public Ethereum network (networkid: 1). Private chains use custom network IDs and aren't connected to the main Ethereum network.

Q: How do I unlock my account?

A: Use:

personal.unlockAccount(accountAddress, "password")

Q: Why can't I see my mined Ether?

A: By default, mining rewards go to your coinbase account (first account). Check with:

eth.getBalance(eth.accounts[0])

Q: How do I set up multiple nodes?

A: Use different data directories (--datadir) and ports (--port, --rpcport) for each node.

๐Ÿ‘‰ Advanced Ethereum development resources