Blog

ideas, experiments, work in progress, freebies & our thoughts on cutting edge tech

Ethereum – Setup your own private blockchain Part -1

Pre-requisites:-

Geth- Geth is the CLI Ethereum client that runs on Windows, Mac, and Linux. Download it here

Mist – The Mist Browser allows us to connect to our private Ethereum blockchain and do fun actions easily. Download it here

Step 1:

Setting up a private Blockchain needs coinbase/etherbase address to be used in genesis.json file so that you have initial ether’s in you wallet account so that you can do meaningfull actions via MIST browser/ web3/ geth console. Create it with following command.

geth –datadir=”{PATH TO BLOCKHAIN DATA}” account new

provide the password you can always remember. Keep note of address generated and password. This command will create “keystore” folder in {PATH TO BLOCKHAIN DATA} folder.

Step 2:

Next generate genesis.json file as below: Important thing to remeber here is, Do not have chainId value of “0”.  It causes issues in submiting transaction/ deploying contracts. Please replace “THIS WILL BE MAIN ACCOUNT ADDRESS” with  the address you created in step 1 above.

{
“config”: {
“chainId”: 8888,
“homesteadBlock”: 0,
“eip155Block”: 0,
“eip158Block”: 0
},
“alloc”      : {
“THIS WILL BE MAIN ACCOUNT ADDRESS ” : { “balance”: “1000000000000000000000”}
},
“coinbase”   : “0x3333333333333333333333333333333333333333”,
“difficulty” : “0x20000”,
“extraData”  : “”,
“gasLimit”   : “0x2fefd8”,
“nonce”      : “0x0000000000000042”,
“mixhash”    : “0x0000000000000000000000000000000000000000000000000000000000000000”,
“parentHash” : “0x0000000000000000000000000000000000000000000000000000000000000000”,
“timestamp”  : “0x00”}

Step 3:

Next its time to actaully initaite the blockhain with genesis.json created above with following command.

geth –datadir=”{PATH TO BLOCKHAIN DATA}” init {PATH TO }genesis.json

This command will create “geth” folder in {PATH TO BLOCKHAIN DATA} folder.

Step 4:

Now its time to actually start geth node with following command.

geth –datadir=”{PATH TO BLOCKHAIN DATA}” –rpc –networkid 8888 –rpcaddr “0.0.0.0” –rpcport “8545”

networkid is needed if we want to add another node to sync with this node in mining. Make sure netwroid is same as chainid in genesis.json.

Step 5:

Now it time to check if everything is fine in our blockchain. Open another terminal and type “geth attach” this will connect to geth running on our node from first terminal. you will be presented with a prompt where we can execute geth commands. Like

eth.getBalance(eth.accounts[0]);

This will show you the balance in your main account address that you created in step 1. and it shall be 1000000000000000000000 as configured in genesis.json.

Step 6:

Now we can start mining which will earn us some more Tokens in out main account address. In geth Prompt execute following command.

 miner.start()

After some time repeat command in step 5 to see that balance has increased. Dont get too excited this is fake Ether, which doesnt have real value in real world:(

Step 7:

If you have already installed MIST, Open it please. Its a desktop broswer and will attach to geth server we had started in step 4 above.

In MIST you can broswe the account you created in step 1. Check its balance. Create more acounts and transfer Ether between accounts. Remember to unlock the account to send or receive the Ethers with following command in geth console-

personal.unlockAccount(eth.accounts[0]);

MIST is also helpful in deploying SMART Contracts which we will explore in next post.

 

 

 

 

 

 

 

Your email address will not be published. Required fields are marked *