Ethereum Private Chain Setup, Genesis Block Creation, and Smart Contract Deployment

·

1. Ethereum Installation, Private Chain Genesis Block Setup, and Node Addition

1.1 Ethereum Installation

Official Download Link: Geth Ethereum

Download the appropriate Geth version for your OS. Verify installation by checking the version:

geth version  

1.2 Private Chain Genesis Block Setup

  1. Create genesis.json:

    {  
      "config": {  
     "chainId": 15,  
     "homesteadBlock": 0,  
     "eip150Block": 0,  
     "eip155Block": 0,  
     "eip158Block": 0  
      },  
      "difficulty": "0x400",  
      "gasLimit": "0x8000000",  
      "alloc": {}  
    }  
  2. Initialize Genesis Block:

    geth --datadir "./chain" init ./genesis.json  
  3. --datadir: Specifies blockchain data storage location.
  4. Start Private Chain:

    geth --datadir "./chain" --nodiscover console 2>> eth_output.log  
  5. --nodiscover: Ensures the chain remains private.
  6. Monitor logs: tail -f eth_output.log (Windows users need Tail.exe).
  7. Account Management:

    personal.newAccount("password") // Create account  
    eth.accounts // List accounts  
    web3.fromWei(eth.getBalance(eth.accounts[0]), "ether") // Check balance  
  8. Mining:

    miner.start(1) // Start mining  
    miner.stop() // Stop mining  

1.3 Adding Nodes to the Private Chain

  1. Retrieve First Node’s enode URL:

    admin.nodeInfo.enode  
  2. Initialize Second Node:

    geth --datadir "./chain2" init ./genesis.json  
    geth --datadir "./chain2" --port 30305 --nodiscover console  
  3. Connect Nodes:

    admin.addPeer("enode://<first-node-id>@127.0.0.1:30303")  
  4. Verify Connection:

    net.peerCount // Should return 1  

2. Explanation of getBlock Fields

| Field | Description |
|--------|-------------|
| difficulty | Block mining difficulty (adjusts dynamically). |
| extraData | Custom metadata or notes. |
| gasLimit | Max gas allowed per block. |
| hash | Block’s unique hash. |
| miner | Miner’s address (reward recipient). |
| nonce | Proof-of-Work hash. |
| transactions | List of transactions or hashes. |

👉 Explore Ethereum development tools


3. Log Output Interpretation


4. Smart Contract Deployment

  1. Write a Simple Contract (e.g., Solidity):

    pragma solidity ^0.8.0;  
    contract SimpleCalc {  
      function f(uint a, uint b) public pure returns (uint) {  
     return a * b;  
      }  
    }  
  2. Compile in Remix: Copy WEB3DEPLOY code.
  3. Deploy via Geth:

    personal.unlockAccount(acc0, "password")  
    miner.start(1)  
    // Paste WEB3DEPLOY code  
  4. Success: Contract mined! appears.
  5. Call Contract Function:

    SimpleCalc.f(3, 8) // Returns 24  

5. Transaction Field Breakdown

👉 Master Ethereum transactions


6. Quick Command Reference

| Command | Purpose |
|---------|---------|
| geth init | Initialize genesis block. |
| miner.start() | Begin mining. |
| eth.sendTransaction() | Send Ether. |


FAQ

Q1: How do I resolve ‘DAG generation’ delays?
A1: DAG generates once per epoch (~30,000 blocks). Pre-download it using geth makedag.

Q2: Why is my transaction pending?
A2: Ensure the sender’s account is unlocked and has sufficient gas.

Q3: How to secure a private chain?
A3: Use --nodiscover and restrict RPC access (--rpcapi).