Setting up a local Ethereum blockchain with geth

Published on 27th Oct, 2016 by David Young

I'm assuming that you already have geth installed. If not then there are instructions for various systems, e.g. ```sudo apt-get install software-properties-common sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install ethereum

from https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu.
A word of warning on this: I tried for a while to get it running on a native smartos zone, with no luck, as Solaris support for some of the libraries is somewhat lacking. On an Ubuntu-flavoured lx branded zone it seems to work just fine.

We need to construct some arguments for geth:

* `--neworkid`: id of the P2P network. Use values > 100 for private nets
* `--identity`: name the node something
* `--nat`: port mapping, de-activate with "none"
* `--datadir`: node info is stored here
* `--nodiscover`: disables peer discovery

e.g.
`geth --networkid 444 --identity ethereum1 --nodiscover --nat none --datadir ~/ethereum1`

These arguments have to be passed to geth every time it is run, so we add the following to `~/.bash_aliases`:
`alias gethparams="geth --networkid 444 --identity ethereum1 --nodiscover --nat none --datadir ~/ethereum1"`

Then we create ourselves an account with `gethparams account new` and set a nice passphrase. This account will be recorded in `$/keystore`. Make a note of the address and passphrase.

For our private test network we have to create a custom genesis block. Write a file called `genesis.json`:

{ "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "difficulty": "0x4000", "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "Custem Ethereum Genesis Block", "gasLimit": "0xffffffff", "alloc": { "eef1f31a46653ffc54c5eb8c7f643413463a182e": { "balance": "1000" } } }


where the address under `alloc` should be set to the address of the account you created earlier.

Initialise the blockchain with our genesis block configuration:
`gethparams init genesis.json`

Then start mining with `gethparams --mine` and very soon your account will start filling up with ethers.
I found it helpful at this point to write a couple more aliases for quickly calling up the miner or the miner-with-console:

alias gethmine="gethparams --mine" alias gethconsole="gethmine --verbosity 0 console"



Visiting the server in another shell we see that the load average has shot up to about 12, so geth is certainly working hard.

Finally, we will do some verification to ensure that it is actually doing what it's supposed to:
`gethparams account list` should tell us that our new account exists;

For running with the javascript console, I'm using `gethparams --mine --verbosity 0 console` to avoid getting flooded with mining status updates.

To see your new account's balance, run `web3.fromWei(eth.getBalance(eth.coinbase),"ether")`
in the console. With the low difficulty level of the test chain we created this balance should increase every few seconds, depending on your processing capacity.

You now have your very own Ethereum blockchain to play with, and an account loaded with ether.