Introduction
When stepping into blockchain development, deploying a private Ethereum network is often the most efficient way to conduct testing and development. A private chain offers security, convenience, and unlimited access to test Ether once mining is enabled.
This guide walks you through setting up a private Ethereum network using Geth (Go Ethereum) and exploring it via the open-source BlockScout blockchain explorer—all deployed via Docker for cross-platform compatibility.
Prerequisites
- Docker: Ensure Docker is installed (Get Docker).
Setting Up the Private Chain
1. Launching the Geth Node
We’ll use an ubuntu:20.04 Docker container to run the Geth client:
docker run -d -it --name ethereum --hostname ethereum --network host ubuntu:20.04Access the container:
docker exec -it ethereum bash2. Installing Geth
Install Geth inside the container:
apt update && apt upgrade -y
apt install software-properties-common vim -y
add-apt-repository -y ppa:ethereum/ethereum
apt update && apt install ethereum -y3. Configuring the Private Chain
Create a Data Directory:
mkdir /dataGenerate a New Account (for mining rewards):
geth --datadir /data account newNote the generated public address (e.g., 0x01461FB75c23ca5a061758120cb085C5100AB122).
Genesis File Setup:
Create /data/genesis.json with the following content:
{
"config": {
"chainId": 9,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0
},
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x20000",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}Initialize the chain:
geth --nousb --datadir /data init /data/genesis.jsonRun Geth with Mining Enabled:
Create /data/run.sh:
geth --snapshot=false \
--identity "localdevnet" \
--networkid 9 \
--datadir /data \
--cache 2048 \
--allow-insecure-unlock \
--gcmode=archive \
--syncmode=full \
--mine \
--miner.threads=1 \
--miner.etherbase=0x01461FB75c23ca5a061758120cb085C5100AB122 \
--http \
--http.addr 0.0.0.0 \
--http.port 24236 \
--http.corsdomain "*" \
--ws \
--ws.addr 0.0.0.0 \
--ws.port 12412 \
--ws.api txpool,web3,eth,debug,ethash,net \
--http.api txpool,web3,eth,debug,ethash,net \
--ws.origins "*" >> /data/geth.log 2>&1Start Geth in the background:
nohup /bin/bash /data/run.sh &Monitor logs:
tail -f /data/geth.logLook for mined potential block to confirm mining is active.
Interact via Geth Console:
geth attach /data/geth.ipc
> eth.accounts
> eth.getBalance(eth.accounts[0])Alternative: Docker-Compose Setup
For a streamlined deployment, use this docker-compose.yml:
version: "3.9"
services:
ethereum:
image: ethereum/client-go:stable
container_name: ethereum
restart: always
network_mode: host
volumes: [ "./data:/data" ]
entrypoint: /bin/sh
command: /data/scripts/docker-entrypoint.shDeploying BlockScout Explorer
1. Clone the Repository:
mkdir ~/deploy && cd ~/deploy
git clone https://github.com/blockscout/blockscout2. Start BlockScout:
cd blockscout/docker
COIN=ETH \
ETHEREUM_JSONRPC_VARIANT=geth \
ETHEREUM_JSONRPC_HTTP_URL=http://localhost:24236 \
ETHEREUM_JSONRPC_WS_URL=ws://localhost:12412 \
BLOCK_TRANSFORMER=base \
NETWORK=Ethereum \
SUBNETWORK=ETH \
make startNote: For PoA chains (e.g., Clique), set BLOCK_TRANSFORMER=clique.
Access the explorer at http://localhost:4000.
FAQs
1. How do I troubleshoot Geth sync issues?
- Ensure ports
24236(HTTP) and12412(WS) are open. Check logs withtail -f /data/geth.log.
2. Can I change the mining reward address?
- Yes. Update
--miner.etherbasein/data/run.shwith a new address.
3. Why is BlockScout slow to load blocks?
- The initial sync may take time. Ensure your node is fully synced (
eth.syncingreturnsfalsein the Geth console).
👉 Explore advanced Ethereum tools for developers.
References
### Key Features: