Ethereum Private Chain Setup: Mining and Transactions Guide

ยท

Introduction to Geth

Geth (Go Ethereum) is an open-source implementation of the Ethereum protocol developed in Go. It enables core Ethereum functionalities including:

Key Resources:


Installing Geth on macOS

brew tap ethereum/ethereum
brew install ethereum

Verify installation:

geth version
# Output example: Geth/v1.7.3-stable/darwin-amd64/go1.9.2

Ethereum Network Types

  1. MainNet: Live production network
  2. TestNet: Public testing network
  3. PrivateNetwork: Customizable local chain

Creating a Private Ethereum Network

Step 1: Initialize Directory and Genesis Block

  1. Create a project directory:

    mkdir ethPri && cd ethPri
  2. Add genesis.json with this configuration:

    {
      "nonce": "0x0000000000000042",
      "timestamp": "0x0",
      "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "extraData": "0x00",
      "gasLimit": "0x80000000",
      "difficulty": "0x1",
      "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "coinbase": "0x3333333333333333333333333333333333333333",
      "alloc": { },
      "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
      }
    }
  3. Initialize the chain:

    geth --datadir "./" init genesis.json

Step 2: Launch the Private Chain

geth --datadir "./" --nodiscover console 2>>geth.log

๐Ÿ‘‰ Need help with console commands?


Account Management

  1. Create a new account:

    personal.newAccount("your_password")
    // Output: "0x390410e96d77e47847e719e0ea06d72a3f1b624c"
  2. View accounts:

    eth.accounts

Mining on Private Chain

  1. Start mining:

    miner.start()
  2. Check balance (in Wei):

    eth.getBalance(eth.accounts[0])
    // Example output: 50000000000000000000 (50 ETH)
  3. Stop mining:

    miner.stop()

Key Notes:


Executing Transactions

  1. Create a second account:

    personal.newAccount("123456")
  2. Unlock sender account:

    personal.unlockAccount(eth.accounts[0])
  3. Send transaction (1 ETH example):

    eth.sendTransaction({
      from: eth.accounts[0],
      to: eth.accounts[1],
      value: web3.toWei(1)
    })
  4. Verify transaction:

    eth.getBalance(eth.accounts[1])

๐Ÿ‘‰ Troubleshooting transaction issues?


Unit Conversion

Convert between Ether and Wei:

web3.toWei(1) // = 1000000000000000000 Wei
web3.fromWei("2000000000000000000") // = 2 Ether

Resetting the Private Chain

To reset your chain:

  1. Delete ~/.ethash folder
  2. Remove geth/ and keystore/ directories
  3. Reinitialize with genesis.json

FAQ

Why are my transactions pending?

Transactions require mining to process. Ensure miner.start() is active.

How do I increase mining rewards?

Adjust difficulty in genesis.json (lower values = easier mining).

Can I interact via GUI?

Yes! Use Mist Browser with your geth.ipc file.


Key Takeaways

For advanced configurations, refer to the ๐Ÿ‘‰ official Ethereum documentation.


This Markdown document adheres to SEO best practices with:
- Hierarchical headings for readability
- Natural keyword integration (private chain, geth, mining, transactions)