Getting Started with Go Ethereum (Geth): Account Creation and Transactions

·

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

  1. Download the latest version of Geth from the official Ethereum website.
  2. Choose the appropriate OS version (e.g., Linux) and extract the downloaded file.
  3. Locate the geth executable 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

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.json

This generates two directories:

Verify the structure with:

tree datadir

Creating and Managing Ethereum Accounts

Creating a New Account

Generate a new account using:

./bin/geth --datadir=./datadir account new

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 console

Mining Ether

  1. Start mining to earn Ether:

    miner.start(1)
  2. Stop mining after a few blocks:

    miner.stop()
  3. 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")

Sending Ether Between Accounts

  1. Unlock the sender account:

    personal.unlockAccount(eth.accounts[0], "123456")
  2. Send 10 Ether:

    eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(10, "ether")})
  3. Mine the transaction:

    miner.start(1)
    miner.stop()
  4. Verify the recipient’s balance:

    web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")

FAQ Section

1. How do I recover a lost account password?

2. Why is my transaction not reflecting in the balance?

3. Can I join the main Ethereum network with this setup?

👉 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.

👉 Explore Ethereum development tools