Setup your Private Ethereum Blockchain in few minutes!

Setup your Private Ethereum Blockchain in few minutes!

Ethereum is a decentralized platform for creating and running the decentralized applications or “dapps” which runs on a distributed network using the blockchain technology. It helps users to settle on agreements directly without having a need for a middleman or third person to interfere in buying, selling, or trading of good and services. Ethereum is a network protocol that allows users to create and run smart contracts, it gathers and runs smart agreements – applications that are, in principle, independent from any outside interference or censorship, as the blockchain is impervious to unauthorized alterations. Smart agreements or contracts run precisely as modified, incredibly reducing the risk of fraudulent and malicious activities, and are self-executing. It works in a similar way as that of any coin-operated machine which carries out agreement terms carefully in a digitally-fashioned way, like when certain conditions are fulfilled, for instance, the exchange of instalments, at that point the product is passed on to the buyer. This reduces all types of costs and saves time and money.

In this blog post, we are going to implement character confirmation system using Blockchain. The basic idea is to store a person’s age which a bartender or salesclerk could reference in lieu of a physical ID such as a driver’s license. We opted for Ethereum since we planned to leverage the smart contracts. The implementation of public blockchain or testnet is is not generally an ideal choice because of long transaction confirmation time, however, setting up a private blockchain is a quick fix.

The simplest approach is to utilize a cloud service like Azure to arrange a private blockchain. This makes the setup easier by providing an Ethereum Blockchain Consortium template, which includes a configurable number of transaction as well as mining nodes. In three stages and around 10 minutes, you can set up a completely working private blockchain in the cloud.

Proof-of-work (PoW) might not be the best possible option while setting up a private blockchain, however, one can opt for Proof-of-Authority(PoA) blockchain using Clique consensus engine provided by Ethereum. To create a PoA network on Azure, we need to set up a server instance using Ubuntu Server 16.04 LTS, which would act as our authority node. Authority nodes don’t require heavy computing resources, thus we can use a smaller VM size (aB1S) choosing default options. Once the VM is up and running, we set up an authority node using the following steps:

Install Ethereum and geth using following commands

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

Setup an authority and transaction account

You need to first generate an authority account and second, will be a prefunded account that can be used to send transactions to the network and be sure to keep track of the password used to create each account!

geth --datadir .ethereum/ account new
> Address: {6203bb870bfb79438b827de3d6b0070d4d2a5f7b}
geth --datadir .ethereum/ account new
> Address: {1808adc011f6e970943d3f28f4d285053d9140ac}

Create a Genesis Block

This can be using puppeth, a CLI tool released with geth 1.6, create and export the definition for your genesis block:

 

puppeth
...
Please specify a network name to administer (no spaces, please)
> clique
...

What would you like to do? (default = stats)
 1. Show network stats
 2. Configure new genesis
 3. Track new remote server
 4. Deploy network components
> 2

Which consensus engine to use? (default = clique)
 1. Ethash - proof-of-work
 2. Clique - proof-of-authority
> 2

How many seconds should blocks take? (default = 15)
> 15

Which accounts are allowed to seal? (mandatory at least one)
> 0x6203bb870bfb79438b827de3d6b0070d4d2a5f7b
> 0x

Which accounts should be pre-funded? (advisable at least one)
> 0x1808adc011f6e970943d3f28f4d285053d9140ac
> 0x

Specify your chain/network ID if you want an explicit one (default = random)
> 42
INFO [02-15|18:24:03] Configured new genesis block

What would you like to do? (default = stats)
 1. Show network stats
 2. Manage existing genesis
 3. Track new remote server
 4. Deploy network components
> 2

 1. Modify existing fork rules
 2. Export genesis configuration
 3. Remove genesis configuration
> 2

Which file to save the genesis into? (default = clique.json)
> genesis.json
INFO [02-15|18:24:22] Exported existing genesis block

The first created authority account is to be used a “sealer” account while the second one as “prefunded account”. For Network/chain ID it is recommended using values below 1000. The values higher than 1000 might create problems later.

Now setup your private Ethereum Instance

Initialize and start your authority geth instance:

geth --datadir .ethereum/ init genesis.json

geth --nodiscover --networkid 42 --datadir .ethereum/ --unlock 0x6203bb870bfb79438b827de3d6b0070d4d2a5f7b --mine --rpc --rpcapi eth,net,web3 --rpcaddr

To unlock the parameter, pass the address of created authority and for rpcaddr, use the private IP address of the VM as displayed in Azure console Network Settings.

Be sure to create an Inbound security rule for port 8545 in your network security group to allow you to connect to your authority node using the standard web3.js library, or in our case, Nethereum for use with Xamarin.

Result: A functional Ethereum blockchain

The above process takes about 20 minutes, and results in a fully functional, private PoA Ethereum blockchain in the cloud. This environment is ideal for decentralized application (DApp) proof-of-concept development and provides fast and free transactions.

 

One thought on “Setup your Private Ethereum Blockchain in few minutes!

  1. A WordPress Commenter

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

Comments are closed.