In this chapter, we'll cover initializing your private Ethereum blockchain, creating the genesis block, running nodes, recording transactions, and mining.
Initializing the Genesis Block
To initialize the genesis block, use the following command:
geth --datadir node1 init node.jsonThis reveals critical information such as:
- Maximum node count
- Database storage location
- Current block status
Launching the Node with Custom Parameters
Before starting the node, configure it using go-ethereum's command-line options. Execute:
geth --datadir node1 --allow-insecure-unlock --nodiscover --syncmode "full" --networkid 7777 --port 30303 --rpc --rpcport 8545 --rpcapi "eth,net,web3" --unlock "f96f9d02cb76cf745d5bd37bd040ac203926f600" --password /Users/wusonglin/node1/password.txt consoleKey Parameters Explained:
datadir: Blockchain data storage path.allow-insecure-unlock: Overrides HTTP account unlocking restrictions (for development only).nodiscover: Disables P2P auto-discovery of nodes.syncmode: Choose"full"(validates all blocks),"fast"(no validation), or"light"(current block only).networkid: Must match the ID in your blockchain config file.rpc: Enables HTTP-RPC for smart contract deployment/calls.rpcapi: Specifies accessible APIs (e.g.,eth,net,web3).
After execution, the console displays the node’s coinbase address, module status, and data directory.
Sending and Validating Transactions
Step 1: Submit a Test Transaction
eth.sendTransaction({
from: eth.accounts[0],
to: "0x91449c31b4f1b6651Acd4bAe4A2067C009750392",
value: web3.toWei(100000, "ether")
});Step 2: Check Transaction Status
With no active miners, transactions remain in the pending pool. Verify with:
txpool.inspect.pendingStep 3: Start Mining
miner.start()- The first mined block includes your transaction.
- Stop mining with
miner.stop().
Recheck the pool to confirm the transaction is processed:
txpool.inspect.pending // Returns empty if successfulFAQ Section
Q1: Why use --allow-insecure-unlock?
This bypasses HTTP unlocking security for local testing. Never use in production.
Q2: What’s the difference between full and fast sync?
Full validates all historical blocks; fast skips validation for quicker synchronization.
Q3: How do I change the default RPC port?
Modify --rpcport (e.g., --rpcport 9000).
👉 Explore advanced Ethereum development tools for more insights.
Q4: Can I mine without transactions?
Yes, but empty blocks waste resources. Always queue transactions first.
👉 Learn about PoA consensus mechanisms to optimize your private chain.
Key Takeaways
- Genesis blocks define your chain’s initial state.
- Customize node parameters for security and performance.
- Mining validates transactions and updates the blockchain.
For further reading, see our guide on PoA consensus best practices.