Introduction to Geth
Geth (Go Ethereum) is an open-source implementation of the Ethereum protocol developed in Go. It enables core Ethereum functionalities including:
- Account management (create/edit/delete)
- Mining initiation
- Ether transfers
- Smart contract deployment/execution
Key Resources:
Installing Geth on macOS
brew tap ethereum/ethereum
brew install ethereumVerify installation:
geth version
# Output example: Geth/v1.7.3-stable/darwin-amd64/go1.9.2Ethereum Network Types
- MainNet: Live production network
- TestNet: Public testing network
- PrivateNetwork: Customizable local chain
Creating a Private Ethereum Network
Step 1: Initialize Directory and Genesis Block
Create a project directory:
mkdir ethPri && cd ethPriAdd
genesis.jsonwith 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 } }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
Create a new account:
personal.newAccount("your_password") // Output: "0x390410e96d77e47847e719e0ea06d72a3f1b624c"View accounts:
eth.accounts
Mining on Private Chain
Start mining:
miner.start()Check balance (in Wei):
eth.getBalance(eth.accounts[0]) // Example output: 50000000000000000000 (50 ETH)Stop mining:
miner.stop()
Key Notes:
- Mining rewards go to the first account by default
- Smart contracts require mining to process
- Delete
~/.ethashif encountering DAG generation issues
Executing Transactions
Create a second account:
personal.newAccount("123456")Unlock sender account:
personal.unlockAccount(eth.accounts[0])Send transaction (1 ETH example):
eth.sendTransaction({ from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1) })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 EtherResetting the Private Chain
To reset your chain:
- Delete
~/.ethashfolder - Remove
geth/andkeystore/directories - 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
- Private chains enable full Ethereum functionality without MainNet costs
- Proper genesis configuration prevents common initialization errors
- Mining is essential for transaction processing and smart contracts
- Always unlock accounts before sending transactions
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)