Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to setup a private ethereum blockchain testnet

These instructions have worked for me on Ubuntu 17.04

Install the go ethereum client (geth)

$ sudo add-apt-repository -y ppa:ethereum/ethereum 
$ sudo apt-get update 
S sudo apt-get install ethereum 

Note: The 'ethereum' package was not found so i installed unstable instead. Try to install ethereum first and if that does not work then try 'ethereum-unstable'

Install Mist

Download and install the appropriate Mist binary from this page. For Ubuntu I downloaded Mist-linux64-0-9-2.deb then ran sudo dpkg -i Mist-linux64-0-9-2.deb

Initialize your local blockchain.

Create a file named genesis.json with the following content in your working directory:

{
    "config": {
        "chainId": 13,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "200",
    "gasLimit": "2100000",
    "alloc": {
    }
}

Note that in most examples you will find online they will have difficulty set a lot higher. Setting it to a low value such as 200, will greatly speed up the mining process.

Initialize the blockchain with geth

$ geth --datadir geth-dir init genesis.json #this will create your blockchain in a sub-folder named geth-dir in the current folder

Create an account on your private blockchain

Run the following command to launch the geth client console:

$ geth --datadir geth-dir console genesis.json

When the geth console launches run the following:

personal.newAccount("password");

Change 'password' to your preferred password for the account.

Take note of the returned address you will use it later

Stop the geth console by pressing Ctrl+d

Fund the account:

Edit the genesis.json file from above:

{
    "config": {
        "chainId": 13,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "difficulty": "200",
    "gasLimit": "2100000",
    "alloc": {
        "PUT THE ADDRESS FROM THE PREVIOUS STEP HERE": { "balance": "11000000000000000000000000" }
    }
}

Save the key files to a safe location

$ cp geth-dir/keystore/* /tmp

Delete the previously generated data directory

$ rm -rf geth-dir

Re-initialize the private blockchain. Note that the difference is that an account has now been created and we have modified the genesis file to fund the account.

$ geth --datadir geth-dir init genesis.json

Restore the key files.

$ cp /tmp/UTC--* geth-dir/keystore

Run the console with a few miner processes.

$ geth --verbosity=6 --datadir geth-dir --networkid 123 --nodiscover  --ipcpath ~/.ethereum/geth.ipc --mine --minerthreads=2 console

Note the value of the ipcpath argument. This lets mist know to connect to the private blockchain. This is platform dependent but you should be able to google for the correct path on your system.

Launch Mist

At this point you should see your account with the funds that you had setup in Mist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment