Installation
👉 Download Geth from the official website
Node Removal
geth removedb --datadir node1
geth removedb --datadir node2
geth removedb --datadir node3Genesis Block Configuration (genesis.json)
{
"config": {
"chainId": 6666,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {}
},
"nonce": "0x0",
"timestamp": "0x5ddf8f3e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0xffffffff",
"difficulty": "0x0200",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}Key Parameters Explained:
- chainId: Unique network identifier (prevents cross-network connections)
- difficulty: Mining complexity (lower values for test chains)
- gasLimit: Transaction processing cap per block
- alloc: Pre-funded accounts (optional for test chains)
Node Initialization
geth --datadir node1 init genesis.json
geth --datadir node2 init genesis.jsonTroubleshooting: If genesis block initialization fails with:
unsupported fork ordering: eip150Block not enabled...Run:
geth removedb --datadir node1Then reinitialize.
Starting Nodes
geth --datadir "node1" --networkid 6666 --port 10010 --http --http.api "eth,net,web3,miner,admin" --http.addr "localhost" --http.port 8546 console 2>node1.log
geth --datadir "node2" --networkid 6666 --port 10011 --http --http.api "eth,net,web3,miner,admin" --http.addr "localhost" --http.port 8547 console 2>node2.log👉 Essential tools for node management
Node Management
View Node Info:
admin.nodeInfoAdd Peer:
admin.addPeer('enode://535bb7b99b8dacd1011484ff3007c77809946b5869e8ab2e30c616bf8eb012d60eecc71e58ebcfbb7c0265b82a4f342e6a107a6b51f6f0ed2d1084c57aba55ae@[::]:10011')List Peers:
admin.peers
Account Operations
List Accounts:
eth.accountsCreate Account:
personal.newAccount("your_password")Import via Private Key:
personal.importRawKey("private_key_without_0x", "password")Unlock Account:
personal.unlockAccount(account_address)Note: For newer Geth versions, add
--allow-insecure-unlockto the node startup command if HTTP unlocking fails.
Transactions & Mining
Check Balance:
web3.fromWei(eth.getBalance(account), 'ether')Transfer ETH:
eth.sendTransaction({from: account1, to: account2, value: web3.toWei(5, 'ether')})Mining:
miner.start(1) // Starts mining with 1 thread miner.stop() // Stops mining
FAQs
1. Why can't I unlock my account via HTTP?
Newer Geth versions disable HTTP unlocking by default for security. Use the --allow-insecure-unlock flag when starting nodes.
2. How do I set the beneficiary address for mining rewards?
miner.setEtherbase(account_address)3. Why are my transactions not processing?
Transactions require mining. Start mining with miner.start() after submitting transactions.
4. How can I connect MetaMask to my private chain?
Add your network via MetaMask's "Custom RPC" option using the HTTP port (e.g., http://localhost:8546).
5. What's the purpose of chainId?
It prevents accidental cross-network connections. Ensure all nodes use the same ID.