What Does an Ethereum Blockchain Look Like? A Guide to Building Your Own Private Ethereum Chain

·

When I first explored Ethereum, I found plenty of resources—including the extensive Homestead Documentation. Yet, these materials felt disconnected from practical understanding. This guide aims to demystify the structure of an Ethereum blockchain by walking you through setting up a private chain.


1. Installing Ethereum (@Ubuntu)

Follow the official instructions:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

2. Generating the Genesis File

Save the following as ~/.ethereum/genesis.json:

{
  "config": {
    "chainID": 1048576,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0
  },
  "alloc": { 
    "0xc1de867b55fdb749be0c927ecf7b19451777042b": { 
      "balance": "20000000000000000000" 
    } 
  },
  "coinbase": "0x0000000000000000000000000000000000000000",
  "difficulty": "0x0400",
  "extraData": "0x00",
  "gasLimit": "0x2fefd8",
  "nonce": "0xdeadbeefdeadbeef",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00"
}

Key Notes:


3. Initializing the Private Chain

cd ~/.ethereum
geth --datadir ~/.ethereum/ init ./genesis.json

4. Account Management

4.1 Importing an Account

echo 22a0b3688dd46ab1a37d6237871913037681d57f628862336bc9c3c468c4a449 > ~/.ethereum/coinbase.key
geth account import ~/.ethereum/coinbase.key

Password-protected keystore files are generated in ~/.ethereum/keystore/.

4.2 Creating a New Account

geth account new

Follow prompts to set a password.

4.3 Listing Accounts

geth account list

5. Starting the Private Chain

geth --identity "TestNode" --rpc --rpcport 8545 --port 30303 --nodiscover console

Flags:


6. Console Operations

6.1 Checking Accounts

> eth.accounts
> eth.coinbase

6.2 Viewing Balances

> eth.getBalance(eth.coinbase)

6.3 Sending Transactions

> personal.unlockAccount(eth.coinbase)
> tx_hash = eth.sendTransaction({
    from: eth.coinbase,
    to: eth.accounts[1],
    value: web3.toWei(1, "ether"),
    gasPrice: 2e9,
    gas: 21000
  })

6.4 Mining

> miner.start(); admin.sleepBlocks(1); miner.stop();

6.5 Transaction Receipts

> eth.getTransactionReceipt(tx_hash)

7. Smart Contracts

7.1 Example: ERC20 Token

pragma solidity ^0.4.0;
contract MyToken {
  string public name;
  string public symbol;
  uint8 public decimals;
  mapping (address => uint256) public balances;
  event Transfer(address indexed from, address indexed to, uint256 value);

  function MyToken(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits) {
    balances[msg.sender] = initialSupply;
    name = tokenName; 
    symbol = tokenSymbol;
    decimals = decimalUnits;
  }

  function transfer(address _to, uint256 _value) {
    require(balances[msg.sender] >= _value);
    balances[msg.sender] -= _value;
    balances[_to] += _value;
    Transfer(msg.sender, _to, _value);
  }

  function balanceOf(address tokenOwner) public constant returns (uint balance) {
    return balances[tokenOwner];
  }
}

7.2 Compiling & Deploying

solc token.sol --bin --abi
> var code = "0x6060...";
> var abi = [...];
> var contract = eth.contract(abi).new(1000000, "Test Token", "TEST", 2, {from: eth.coinbase, data: code, gas: 1e6});

7.3 Interacting with Contracts

> contract.balanceOf.call(eth.coinbase);
> contract.transfer.sendTransaction(eth.accounts[1], 100, {from: eth.coinbase, gas: 1e5});

8. Ethereum Keys & Addresses


9. Gas, GasLimit, and GasPrice

Formula: Transaction Cost = gasUsed * gasPrice


10. FAQs

Q1: How is Ethereum’s total supply calculated?

A: Initial supply was 72M ETH, with annual issuance capped at 25% (~18M). Current circulating supply: ~98M (2023).

Q2: Why does my transaction fail?

A: Common causes: insufficient gas, incorrect nonce, or low balance. Check eth.getTransactionReceipt() for details.

Q3: What’s the difference between PoW and PoS in Ethereum?

A: PoW (Ethash) is used in Homestead; PoS (Casper) will replace it in Metropolis to improve scalability.

👉 Explore Ethereum further


Final Notes:

Need more help? Join the Ethereum community!