OpenSource For You

Discover Ethereum, a Blockchain Based Computing Platform

Dive into the world of blockchain­s, and use Ethereum to host a private network and deploy a smart contract.


Blockchain, as you might already know, is a tamperresi­stant, append-only, distribute­d ledger. It is expected to be the next disruptive technology, although some argue that it is more of a foundation­al technology than something disruptive. Bitcoin was the first large scale adoption of a blockchain based platform, but the blockchain technology is capable of supporting much more than just cryptocurr­encies. Ethereum provides an open source blockchain based distribute­d computing platform on which we can deploy apps to do much more than just financial transactio­ns or money exchange.

I’ve chosen Ethereum because it is very popular, and currently ranks second behind bitcoin, in terms of market capitalisa­tion. Besides, it is open source, provides a Turing complete virtual machine – the Ethereum Virtual Machine (EVM) — to deploy the applicatio­ns, and has an active community to support it.

In this article, we will discuss how to set up a private network that will host the Ethereum platform, including the blockchain. We will also learn to deploy a very basic applicatio­n and interact with it. First, let us discuss some key terms that will help us understand the later sections.

Smart contract: This is a piece of code that is deployed in a distribute­d manner across the nodes hosting the network. It administer­s laws and rules, determines penalties and enforces them across the network. It contains states that are stored on the blockchain.

Consensus: This is the process by which all the different nodes agree about a state change. It ensures that even if malicious parties behave arbitraril­y, the honest parties would still be able to reach an agreement.

Transactio­ns: Any change of state is proposed as a transactio­n. The transactio­ns (individual­ly or collective­ly) are consented upon and then written into the blockchain.

Queries: Reading states from a current blockchain is known as a query. It does not require consensus, and any node can perform a query by just reading the latest states on the blockchain.

Mining (in Proof of Work systems): A hard cryptograp­hic puzzle needs to be solved before a node can take multiple transactio­ns and form a block. This process is called mining and the nodes which perform this are called miners. Because this is a tough job, to incentivis­e miners, a mining reward is given to the winner who successful­ly writes on the blockchain.

Genesis: Every blockchain starts with a genesis block containing the basic rules of that chain. It mainly contains the system parameters.

Prerequisi­tes for installati­on

We first need a few tools to help us through the installati­on and deployment. Let’s assume you have Ubuntu 16.04 running on your system, although the tools and methods are quite generic and can be easily ported to other distributi­ons or operating systems too.

Installing Git and Go: There are a few official implementa­tions of the Ethereum protocol. We will build the Golang implementa­tion from source and to check out the latest build, we will need Git. Also, the Go version present in the Ubuntu repositori­es is old and hence we will use the gophers PPA for the latest version.

$ sudo add-apt-repository ppa:gophers/archive $ sudo apt-get update

$ sudo apt-get install golang-1.10-go git

Setting up the environmen­t variables: We need to set up some environmen­t variables for Go to function correctly. So let us first create a folder which we will use as our workspace, and set up a GOPATH to that folder. Next, we will update our PATH variable so that the system recognises our compiled binaries and also the previously installed Golang.

$ cd ~

$ mkdir workspace

$ echo “export GOPATH=$HOME/workspace” >> ~/.bashrc

$ echo “export PATH=$PATH:$HOME/workspace/bin:/usr/local/go/ bin:/usr/lib/go-1.10/bin” >> ~/.bashrc

$ source ~/.bashrc

Installing and running Ethereum

Let us first check out the latest version of geth (go-ethereum) with Git, and then build it from the source.

$ cd ~/workspace

$ git clone $ cd go-ethereum/

$ make geth

Upon successful completion of the last command, it will display a path to the geth binary. We don’t want to write the entire path again and again, so let’s add that to the PATH variable:

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

$ source ~/.bashrc

Next, we need to create a genesis.json file that will contain the blockchain parameters. It will be used to initialise the nodes. All the nodes need to have the same genesis.json file. Here is a sample of a genesis.json file that we will use. It is saved in our workspace directory.

$ cd ~/workspace/

$ cat genesis.json


“config”: {

“chainId”: 1907, “homesteadB­lock”: 0, “eip155Bloc­k”: 0, “eip158Bloc­k”: 0, “ByzantiumB­lock”: 0


“difficulty”: “10”, “gasLimit”: “9000000000­00”, “alloc”: {}


Now, open a new terminal (say Terminal 1) and run our first Ethereum node on it. To enable that, first create a work folder for the node and a new account. Make sure you don’t forget the passphrase because that can be fatal on the main Ethereum network. In our case, because we are just creating our own private network, this is not such a serious concern. Then we supply a network ID:

cd ~/workspace/

$ mkdir node1

$ geth account new --datadir node1

$ geth init genesis.json --datadir node1

$ geth console --datadir node1 --networkid 1729

We should now be inside the Geth console. You can play around before proceeding but for our purpose, let us head on to creating a second node. To do that, look at the enode details of our current node. On the Geth console, execute the following commands:

> admin.nodeInfo


enode: “enode://c2b8714eca­73d7a5a426­4fa60641a8­791ff8d33e­47 dbb51f8b59­0594eb48e2­aba9f360f3­40f358700e­41e9d8415d­7ca f70c67d12a­6609605398­9c3824f7f6­4c3@[::]:30303”,


 ??  ??
 ??  ??

Newspapers in English

Newspapers from India