Ethereum Logo

I’ve been interested in the Ethereum blockchain for a while now, particularly the “Smart Contract” feature. A smart contract is a script deployed on the blockchain that miners execute in exchange for a variable amount of money depending on the script’s content. But to test these smart contracts, you need to set up a private Ethereum network. This tutorial requires a minimal understanding of the Ethereum blockchain and “Proof of Work” systems.

The network will consist of three components:

  • Ethereum Core (the part that records all blockchain information and manages the Ethereum protocol).
  • Ethereum Console (console for executing commands on the private network, notably starting miners responsible for executing smart contracts and validating transactions).
  • Wallet Client (the wallet for managing contracts and Ether).

Step 1: Compiling geth

Geth is the program containing Ethereum Core and Ethereum Console. First, download the sources from here, then install golang and build-essential:

sudo apt-get install -y build-essential golang

To build geth, run:

make geth

The compiled program is located in “build/bin/geth”.

Step 2: Starting Ethereum Core

Ethereum Core is the foundation of the private network. At startup, a .ipc file is generated containing all information about our network – it will be used to connect Ethereum Core to Ethereum Console and the Wallet Client. Start it with:

./geth --dev --port 1250 --maxpeers 0 --datadir "data"

Step 3: The Ethereum Console

This console attaches to Ethereum Core to control the network. To start the Ethereum Console, run the following command in a Linux terminal while keeping Ethereum Core running:

./geth --dev attach ipc:data/geth.ipc

Then create accounts that will be used to test contracts in the now-open Ethereum Console:

personal.newAccount('choose-a-password');

Finally, start a miner that will validate transactions:

miner.start();

Stop the miner:

miner.stop();

Step 4: Installing the Wallet in Private Network Mode

Download the Ethereum wallet – it is the standard Ethereum wallet client that we will launch with a command to connect to our private network. Once installed, start Ethereum Core if it is not already running to allow the wallet to synchronize, then open a new terminal while keeping Ethereum Core and Ethereum Console running and type:

ethereumwallet --rpc go-ethereum/build/bin/data/geth.ipc

Step 5: Commands to Run at Each Private Network Startup

./geth --dev --port 1250 --maxpeers 0 --datadir "data"

./geth --dev attach ipc:data/geth.ipc
miner.start();

ethereumwallet --rpc go-ethereum/build/bin/data/geth.ipc