Dis­cover Ethereum, a Blockchain Based Com­put­ing Plat­form

Dive into the world of blockchains, and use Ethereum to host a pri­vate net­work and de­ploy a smart con­tract.

OpenSource For You - - Contents -

Blockchain, as you might al­ready know, is a tam­per­re­sis­tant, ap­pend-only, dis­trib­uted ledger. It is ex­pected to be the next dis­rup­tive tech­nol­ogy, although some ar­gue that it is more of a foun­da­tional tech­nol­ogy than some­thing dis­rup­tive. Bit­coin was the first large scale adop­tion of a blockchain based plat­form, but the blockchain tech­nol­ogy is ca­pa­ble of sup­port­ing much more than just cryp­tocur­ren­cies. Ethereum pro­vides an open source blockchain based dis­trib­uted com­put­ing plat­form on which we can de­ploy apps to do much more than just fi­nan­cial trans­ac­tions or money ex­change.

I’ve cho­sen Ethereum be­cause it is very pop­u­lar, and cur­rently ranks sec­ond be­hind bit­coin, in terms of mar­ket cap­i­tal­i­sa­tion. Be­sides, it is open source, pro­vides a Tur­ing com­plete vir­tual ma­chine – the Ethereum Vir­tual Ma­chine (EVM) — to de­ploy the ap­pli­ca­tions, and has an ac­tive com­mu­nity to sup­port it.

In this ar­ti­cle, we will dis­cuss how to set up a pri­vate net­work that will host the Ethereum plat­form, in­clud­ing the blockchain. We will also learn to de­ploy a very ba­sic ap­pli­ca­tion and in­ter­act with it. First, let us dis­cuss some key terms that will help us un­der­stand the later sec­tions.

Smart con­tract: This is a piece of code that is de­ployed in a dis­trib­uted man­ner across the nodes host­ing the net­work. It ad­min­is­ters laws and rules, de­ter­mines penal­ties and en­forces them across the net­work. It con­tains states that are stored on the blockchain.

Con­sen­sus: This is the process by which all the dif­fer­ent nodes agree about a state change. It en­sures that even if ma­li­cious par­ties be­have ar­bi­trar­ily, the hon­est par­ties would still be able to reach an agree­ment.

Trans­ac­tions: Any change of state is pro­posed as a trans­ac­tion. The trans­ac­tions (in­di­vid­u­ally or col­lec­tively) are con­sented upon and then writ­ten into the blockchain.

Queries: Read­ing states from a cur­rent blockchain is known as a query. It does not re­quire con­sen­sus, and any node can per­form a query by just read­ing the lat­est states on the blockchain.

Min­ing (in Proof of Work sys­tems): A hard cryp­to­graphic puzzle needs to be solved be­fore a node can take mul­ti­ple trans­ac­tions and form a block. This process is called min­ing and the nodes which per­form this are called min­ers. Be­cause this is a tough job, to in­cen­tivise min­ers, a min­ing re­ward is given to the win­ner who suc­cess­fully writes on the blockchain.

Gen­e­sis: Every blockchain starts with a gen­e­sis block con­tain­ing the ba­sic rules of that chain. It mainly con­tains the sys­tem pa­ram­e­ters.

Pre­req­ui­sites for in­stal­la­tion

We first need a few tools to help us through the in­stal­la­tion and de­ploy­ment. Let’s as­sume you have Ubuntu 16.04 run­ning on your sys­tem, although the tools and meth­ods are quite generic and can be eas­ily ported to other dis­tri­bu­tions or op­er­at­ing sys­tems too.

In­stalling Git and Go: There are a few of­fi­cial im­ple­men­ta­tions of the Ethereum pro­to­col. We will build the Golang im­ple­men­ta­tion from source and to check out the lat­est build, we will need Git. Also, the Go ver­sion present in the Ubuntu repos­i­to­ries is old and hence we will use the go­phers PPA for the lat­est ver­sion.

$ sudo add-apt-repos­i­tory ppa:go­phers/ar­chive $ sudo apt-get up­date

$ sudo apt-get in­stall golang-1.10-go git

Set­ting up the en­vi­ron­ment vari­ables: We need to set up some en­vi­ron­ment vari­ables for Go to func­tion cor­rectly. So let us first cre­ate a folder which we will use as our workspace, and set up a GOPATH to that folder. Next, we will up­date our PATH vari­able so that the sys­tem recog­nises our com­piled bi­na­ries and also the pre­vi­ously in­stalled Golang.

$ cd ~

$ mkdir workspace

$ echo “ex­port GOPATH=$HOME/workspace” >> ~/.bashrc

$ echo “ex­port PATH=$PATH:$HOME/workspace/bin:/usr/lo­cal/go/ bin:/usr/lib/go-1.10/bin” >> ~/.bashrc

$ source ~/.bashrc

In­stalling and run­ning Ethereum

Let us first check out the lat­est ver­sion of geth (go-ethereum) with Git, and then build it from the source.

$ cd ~/workspace

$ git clone https://github.com/ethereum/go-ethereum.git $ cd go-ethereum/

$ make geth

Upon suc­cess­ful com­ple­tion of the last com­mand, it will dis­play a path to the geth bi­nary. We don’t want to write the en­tire path again and again, so let’s add that to the PATH vari­able:

$ echo “ex­port PATH=$PATH:$HOME/workspace/go-ethereum/build/ bin” >> ~/.bashrc

$ source ~/.bashrc

Next, we need to cre­ate a gen­e­sis.json file that will con­tain the blockchain pa­ram­e­ters. It will be used to ini­tialise the nodes. All the nodes need to have the same gen­e­sis.json file. Here is a sam­ple of a gen­e­sis.json file that we will use. It is saved in our workspace di­rec­tory.

$ cd ~/workspace/

$ cat gen­e­sis.json

{

“con­fig”: {

“chainId”: 1907, “home­stead­Block”: 0, “eip155Block”: 0, “eip158Block”: 0, “Byzan­tiumBlock”: 0

},

“dif­fi­culty”: “10”, “gasLimit”: “900000000000”, “al­loc”: {}

}

Now, open a new ter­mi­nal (say Ter­mi­nal 1) and run our first Ethereum node on it. To en­able that, first cre­ate a work folder for the node and a new ac­count. Make sure you don’t for­get the passphrase be­cause that can be fa­tal on the main Ethereum net­work. In our case, be­cause we are just cre­at­ing our own pri­vate net­work, this is not such a se­ri­ous con­cern. Then we sup­ply a net­work ID:

cd ~/workspace/

$ mkdir node1

$ geth ac­count new --datadir node1

$ geth init gen­e­sis.json --datadir node1

$ geth con­sole --datadir node1 --net­workid 1729

We should now be in­side the Geth con­sole. You can play around be­fore pro­ceed­ing but for our pur­pose, let us head on to cre­at­ing a sec­ond node. To do that, look at the en­ode de­tails of our cur­rent node. On the Geth con­sole, ex­e­cute the fol­low­ing com­mands:

> ad­min.nodeInfo

{

en­ode: “en­ode://c2b8714e­ca73d7a5a4264­fa60641a8791f­f8d33e47 db­b51f8b590594e­b48e2a­ba9f360f340f358700e41e9d8415d7ca f70c67d12a66096053989c3824f7f64c3@[::]:30303”,

………

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.