Building a Private Blockchain with Ethereum

As title says this is a summary on how to setup your private Blockchain with Ethereum

Requirements:

Difficulty level: CTRL+C/CTRL+V a.k.a DigitalOcean style

1) Install Ethereum (with repo):

sudo apt-get install software-properties-common

sudo add-apt-repository -y ppa:ethereum/ethereum

sudo apt-get update

sudo apt-get install ethereum


2) Create an Ethereum Account/Address:

geth account new


Output:
[email protected]:/home/ubuntu# geth account new
WARN [07-04|21:27:58] No etherbase set and no accounts found as default
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {YOUR ETHEREUM ADDRESS}

3) Generate the ‘Genesis’ block of your blockchain with:

geth init genesis.json

genesis.json format is:
{
“config”: {
“chainId”: 13,
“homesteadBlock”: 0,
“eip155Block”: 0,
“eip158Block”: 0
},

“difficulty”: “200000000”,
“gasLimit”: “2100000”,
“alloc”: {
“{YOUR ETHEREUM ADDRESS GENERATED FROM ABOVE”: { “balance”: “100000000” }
}
}

NOTE: On “chainId” put your networkid

3) Run the first node with (networkid must be different from (1=Frontier, 2=Morden (disused), 3=Ropsten and 4) :

geth –datadir=”/tmp/eth01” -verbosity 6 –port 30301 –networkid 13 –nodiscover console

You can run this command under screen/NOHUP or any other way to keep it on background (pls not systemd).

NOTE: All the nodes must start the blockchain from the same genesis.json file (The first block).

To dinamically add other nodes you must follow the same steps from above (install eth, genesis from same block & run node on same net id) then add the node as an Admin peer with:

From the geth console run this to get your node public key:

admin.nodeInfo.enode

Output:

“enode://0e6b3bf7242d5c731e3da325eb7a2c2bd08be3acecf701d410a70043110a491e8[email protected][::]:30301?discport=0”

This is your [email protected]:30303 and its the identifier for the node, to make the nodes see eachother you need to add them as peers with:

admin.addPeer(“enode://[email protected]:30303”)


How to check if peers are UP:

net.peerCount

or

admin.peers


How to add statically Admin Peers: Create a .json file inside the data dir with all the public-keys of the nodes that are allowed on the multi-node private blockchain, in this case:
/tmp/eth01/static-nodes.json

Format:

[ “enode://[email protected]:port” , “enode://[email protected]:port” ]


Your blockchain is ready for transactions/testing/development

Tested on multiple Ubuntu instances, for testing purposes you can also run multiple nodes on the same host or locally on your computer just change ports or you will get binding errors/exceptions.

Make sure the Ethereum nodes can see eachother on port 30303 (Test with telnet) locally or via wan.