Keywords: Go Ethereum, Geth, Ethereum accounts, private network, blockchain transactions, mining, genesis.json, keystore
Introduction to Go Ethereum (Geth)
Go Ethereum (Geth) is the official Go implementation of the Ethereum protocol, allowing users to interact with the Ethereum blockchain. This guide walks you through setting up a private network, creating accounts, and executing transactions using Geth.
Setting Up Your Private Ethereum Network
Step 1: Download and Install Geth
- Download the latest version of Geth from the official Ethereum website.
- Choose the appropriate OS version (e.g., Linux) and extract the downloaded file.
- Locate the
gethexecutable file in the extracted folder.
Step 2: Configure Directory Structure
Run the following commands in your terminal to set up the directory structure:
mkdir go
cd go
mkdir bin- The
gethfile should be placed in/home/go/bin.
Step 3: Initialize the Private Network
Create a genesis.json configuration file in the go folder to define your private blockchain's initial state. Initialize the network with:
./bin/geth --datadir=./datadir init genesis.jsonThis generates two directories:
geth: Stores blockchain data.keystore: Holds encrypted account keys.
Verify the structure with:
tree datadirCreating and Managing Ethereum Accounts
Creating a New Account
Generate a new account using:
./bin/geth --datadir=./datadir account new- Set a secure password (e.g.,
123456). - The public address (e.g.,
0x5921A6Ee66Bb12B4C27592e3D6452B2226Dbaa7F) will be stored inkeystore.
Viewing Account Details
For readability, install jq and run:
cat datadir/keystore/UTC--2022-03-13T15-06-39.931303932Z--5921a6ee66bb12b4c27592e3d6452b2226dbaa7f | jq '.'Interacting with the Geth Console
Start the console with:
./bin/geth --datadir=./datadir consoleMining Ether
Start mining to earn Ether:
miner.start(1)Stop mining after a few blocks:
miner.stop()Check mined blocks:
eth.blockNumber
Checking Account Balances
Convert balance to Ether:
web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")Executing Transactions
Creating a Second Account
Generate another account:
personal.newAccount("123456")- New address:
0x2A1a50f37F6514DCD4500CFC50D880AB0130721f.
Sending Ether Between Accounts
Unlock the sender account:
personal.unlockAccount(eth.accounts[0], "123456")Send 10 Ether:
eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")})Mine the transaction:
miner.start(1) miner.stop()Verify the recipient’s balance:
web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
FAQ Section
1. How do I recover a lost account password?
- The keystore file is encrypted. Without the password, account access is irrecoverable. Always store passwords securely.
2. Why is my transaction not reflecting in the balance?
- Transactions require mining to be included in a block. Start the miner to process pending transactions.
3. Can I join the main Ethereum network with this setup?
- Yes. Omit the
--datadirandgenesis.jsonflags to sync with the mainnet.
👉 Learn more about advanced Geth configurations
Conclusion
This guide covered setting up a private Ethereum network, creating accounts, mining Ether, and executing transactions. For further exploration, refer to the official Geth documentation.