Introduction
Amidst the blockchain revolution, Ethereum stands out as the leading platform for programmable smart contracts. While alternatives like Hyperledger and EOS exist, Ethereum remains the most mature solution. This guide walks you through setting up your own Ethereum private chain using Geth (command-line client) and Mist (visual wallet).
1. Downloading Geth and Mist Clients
Ethereum Client Types
- Geth: A Go-based command-line interface (CLI) for interacting with the Ethereum network. Widely used due to its reliability.
- Mist: A graphical wallet that visualizes account balances and enables smart contract deployment.
Download Links (Windows)
2. Genesis Block Configuration (genesis.json)
{
"config": {
"chainId": 101,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x400",
"gasLimit": "0xffffffff",
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}Key Parameters
| Parameter | Purpose |
|---|---|
chainId | Unique network ID (avoid 1, the mainnet) |
difficulty | Mining difficulty (lower = easier) |
gasLimit | Minimum gas consumption per block |
3. Initialize the Node
geth --datadir data0 init genesis.jsondata0: Directory for node data (avoid system paths like%cd%\\chain).
4. Start the Geth Node
geth --identity "TestNode1" --datadir "data0" --rpc --rpcapi "db,eth,net,web3" --rpcaddr "127.0.0.1" --rpcport "8486" --port "30304" --networkid "29382" consoleCommand Breakdown
| Flag | Functionality |
|---|---|
--identity | Node name (e.g., "TestNode1") |
--rpcapi | Enabled APIs (e.g., eth, web3) |
--networkid | Must match across all private nodes |
5. Essential Geth Commands
// Create an account
personal.newAccount("123456");
// List accounts
eth.accounts;
// Unlock an account
personal.unlockAccount(eth.accounts[0], "123456");
// Check balance
eth.getBalance(eth.accounts[0]);
// Start/stop mining
miner.start();
miner.stop();6. Multi-Node Setup
Add a Second Node
Initialize:
geth --datadir data1 init genesis.jsonStart:
geth --identity "TestNode2" --datadir "data1" --rpcport "8487" --port "30305" --networkid "29382" consoleConnect nodes:
admin.addPeer("enode://...@[YOUR_IP]:30304");
7. Launch Mist Wallet
Primary Node:
mist.exe --rpc \\\\.\\pipe\\data0\\geth\\geth.ipcSecondary Node (Read-Only):
mist.exe --rpc http://127.0.0.1:8545
8. Deploy Smart Contracts via Mist
Example Contract (Token.sol):
pragma solidity ^0.4.18;
contract Token {
mapping (address => uint) public balancesOf;
address public owner;
function Token() public {
owner = msg.sender;
balancesOf[msg.sender] = 10000;
}
// ... (additional functions)
}- Deploy via Mist UI.
- Mine the transaction (
miner.start()).
FAQs
Q: Why use a private chain?
A: For testing smart contracts without real ETH or mainnet fees.
Q: How do I reset the chain?
A: Delete the data0/data1 folders and reinitialize.
Q: Can I sync private chains across machines?
A: Yes—ensure identical genesis.json and networkid.
Conclusion
This setup lays the groundwork for Ethereum development. Future topics include Solidity best practices and advanced contract deployment.