Building your Private Blockchain with Ethereum
As title says this is a summary on how to setup your private Blockchain with Ethereum
Requirements:
- 2+ Ubuntu 16 servers/vps or locally on your computer
- Geth client
Difficulty level: CTRL+C/CTRL+V a.k.a DigitalOcean style
- 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:
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
- 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.
NOTE:
All the nodes must start the blockchain from the same genesis.json file (The first block).
To dynamically 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://0e6b3bf7242d5c731e3da325eb7a2c2bd08be3acecf701d410a70043110a491e8b93f05b97222040b27aa6e32fb0fea05d3572e069f646a5b0c793695f9e1f52@[::]:30301?discport=0"
This is your public-key@ip:30303 and its the identifier for the node,
to make the nodes see each other you need to add them as peers with:
admin.addPeer("enode://public-key@ip: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://pubkey@ip-of-other-node:port" , "enode://pubkey@ip-of-other-node2: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.
Comments
Post a Comment