Setting up your private Ethereum blockchain

Hi all,

today we will cover the process of setting up your own private Ethereum blockchain with the help of Dappros Platform. The standard version of our platform uses Ethereum blockchain network at its core and also provides additional useful services and infrastructure to make the whole blockchain experience easier for you while reducing integration and roll-out time. Among many, Dappros Platform offers a convenient REST JSON API layer (check our API documentation for more details), web interface and many other useful bits.

When it comes to deployment, Dappros Platform can be:

(1) used from the cloud (and this is what most of our customers choose) in which case not setup needs to be carried out – it’s already there

(2) installed on-premise (which may be in your datacentre or any 3rd party data centre)

On-premise option requires installation and Dappros team normally takes care of this for our clients, however we thought sharing our documentation online might help those clients and developers who are looking to set up their own private Ethereum (or Ethereum compatible) networks where they might have a similar set up like us (Ethereum at the core, Node.js application for the API layer, MongoDB for database and caching layer, and IPFS for distributed files storage).

Without further ado please find below the step-by-step guidance on installing your own private Ethereum blockchain network using the example of Dappros Platform set up.

We are also considering open-sourcing our application and API layer and the only reservation we have so far is whether we are ready at this stage to allocate enough resources to separately manage the open-source project development in addition to all our work with enterprise clients. If you find this manual useful and you are interested to have a look at our Application and API layer please do provide your feedback which will help us to make an informed decision.

Private Ethereum blockchain (with Dappros Platform Application/API layer) Deployment Guide

  • Note: This document only provides support for Linux Ubuntu based systems

Pre-requisites

Hardware:

  • 8gb ram and 50 gb for Dev/QA
  • 16gb ram and 500gb for Prod
  • Recommended OS: Ubuntu 18.04 (bionic repositories)
  • Dappros Platform code from gitlab

Setup Blockchain Node

 

  • Install Geth:

 

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

 

 

  • Create a Genesis file:

 

Copy this file and name it customGenesis.json:

Current production genesis file:-

{
    “config”: {
        “chainId”: 13,
        “homesteadBlock”: 0,

        “eip150Block”: 0,
        “eip155Block”: 0,
        “eip158Block”: 0
    },
    “difficulty”: “0”,
    “gasLimit”: “2100000”,
    “alloc”: {
    }
}

* Add this file in your home directory (/home/). If you will change directory, you have to specify in the command during initialization of genesis file.

TF: Chain ID is arbitrary, you can put there pretty much any number except 1 (which stands for Ethereum main net), just need to make sure you specify same Chain ID when connecting multiple peers / nodes to same network.

 

  • Initialize the genesis file:

 

  • Run command
geth init ./customGenesis.json

* Remember to be in the directory where you want to store the network artifacts during running this command. Also, specify your genesis file path accordingly. 

TF: example of output: 

 

 

 

  • Creating a new account on Geth:

 

  • Run command
geth account new

* Remember to be in the directory where you have initialized the genesis file during running this command.

 

  • Enter a password (Remember the password for future)

 

  TF: output example: 

 

 

  • Create a file to start auto mining: (Name it auto_start_mining.js)

 

 

var mining_threads = 1

function checkWork() {
  if (eth.pendingTransactions.length > 0) {
      if (eth.mining) return;
      console.log(“== Pending transactions! Mining…”);
      miner.start(mining_threads);
  } else {
      miner.stop();
      console.log(“== No transactions! Mining stopped.”);
  }
}

eth.filter(“latest”, function(err, block) { checkWork(); });
eth.filter(“pending”, function(err, block) { checkWork(); });

checkWork();

 

* Create this file in the home directory. If you wish to store it somewhere else, You have to specify it in the below command which is for starting the network.

 

 

  • Starting a private network:

 

 

 

  • Run the command

 

 

geth –rpc –rpcport “8545” –rpcaddr “127.0.0.1” –rpccorsdomain “*” –ws –wsorigins “*” –wsaddr “127.0.0.1” –wsport “8546” –rpcapi “web3,personal,eth,net” –wsapi personal,web3,eth,net,db –unlock 0 –preload “auto_start_mining.js” –cache 2048 “–allow-insecure-unlock” console

 

 

  • Enter password: *****

 

TF: enter here the password you have created earlier for your Geth account

 

 

  • Verify Installation:

 

 

 

  • Run the command

 

$ eth.blockNumber

* Run this command inside the geth console

Response: 0

 

  • Run the command

 

$ miner.start()

* Run this command inside the geth console

Response: Generating DAG in Progress …

Wait till the percentage reaches “100” first time and then after that run the below command.

 

  • Run the command

 

$ eth.getBalance(eth.coinbase)

It should not return 0. 

Type “exit” to exit the geth console.

TF: note this will effectively quit the geth / mining process so you want to put this into the background using “screen” or similar process management tool.

Setup Mongo DB

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition

 

  • Import the public key used by the package management system

 

wget -qO – https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add –

 

  • Import the public key used by the package management system

 

echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

 

  • Reload local package

 

sudo apt-get update

 

  • Install MongoDB package

 

sudo apt-get install -y mongodb-org

* Steps above are for Ubuntu 18.04. Please follow the below link for other versions & machines. 

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ 

 

  • Start Mongo DB

 

sudo service mongod start

 

  • Go Inside MongoDB Terminal

 

mongo

 

  • Stop Mongo DB (Not necessary)

 

sudo service mongod stop

TF: for me MongoDB didn’t start immediately and it was showing this error:

What helped is follow this guidance: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition

sudo systemctl start mongod

sudo systemctl daemon-reload

sudo systemctl enable mongod

sudo systemctl restart mongod

sudo systemctl status mongod

Only after manipulations above + system reboot it worked fine for me:

Setup IPFS

(Dappros Platform stores images for example for user profile photos, file attachments and other binary data in IPFS)

 

  • Download the IPFS tar file for your system. Visit the below link.

 

https://dist.ipfs.io/#go-ipfs

TF: I used “wget https://dist.ipfs.io/go-ipfs/v0.4.23/go-ipfs_v0.4.23_linux-amd64.tar.gz” in my case

 

  • Extract the tar file

 

$ tar xvfz go-ipfs.tar.gz [replace with your downloaded ipfs file name]

 

  • Go inside the IPFS directory

 

$ cd go-ipfs

 

  • Install IPFS using bash command

 

$ ./install.sh

 

  • Go to the home directory

 

$ cd ~

TF: I’ve had to do cd /home/ here as in my Digital Ocean set up I was logged as root, so “cd ~” takes to /root/ but let’s use /home/ to be consistent with the rest of the manual. 

 

  • Initialize IPFS

 

$ ipfs init

 

  • Start IPFS

 

$ ipfs daemon

IPFS runs on port 5001.

* For more information and detailed download procedure visit the below link.

  https://docs.ipfs.io/guides/guides/install/

Setup Node and NPM

 

  • Install curl if required

 

$ sudo apt-get install curl

 

  • Add node.js PPA in your machine

 

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –

 

  • Install node.js

 

$ sudo apt-get install nodejs

 

  • Check version to validate

 

$ node -v 

v10.16.1

* For more information and detailed download procedure visit the below link.

    https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/

Setup Dappros Platform

 

  • Start Geth

 

$ geth –rpc –rpcport “8545” –rpcaddr “127.0.0.1” –rpccorsdomain “*” –ws –wsorigins “*” –wsaddr “127.0.0.1” –wsport “8546” –rpcapi “web3,personal,eth,net” –wsapi personal,web3,eth,net,db –unlock 0 –preload “auto_start_mining.js” –cache 2048 “–allow-insecure-unlock” console

TF: it’s better to start it via screen process management so it runs in background, here is the sequence:

sudo apt install screen

screen geth –rpc –rpcport “8545” –rpcaddr “127.0.0.1” –rpccorsdomain “*” –ws –wsorigins “*” –wsaddr “127.0.0.1” –wsport “8546” –rpcapi “web3,personal,eth,net” –wsapi personal,web3,eth,net,db –unlock 0 –preload “auto_start_mining.js” –cache 2048 “–allow-insecure-unlock” console

[enter your geth password and afterwards you can detach from this screen using Ctrl+a Ctrl+d]

For more information on using screen: https://linuxize.com/post/how-to-use-linux-screen/

 

 

  • Start Mongo DB

 

$ sudo service mongod start

TF: no need to start Mongo via screen, it runs in background automatically. Use 

sudo systemctl status mongod

to check it’s running without errors.

 

 

  • Start IPFS daemon

 

$ ipfs daemon

TF: same thing with screen here:

screen ipfs daemon

detach using Ctrl+a Ctrl+d

 

 

  • Clone Dappros Platform repository

 

$ git clone https://gitlab.com/dappros/dapprosplatform.git

 

 

  • Go inside the directory

 

$ cd dapprosplatform

 

 

  • Create an .env file

 

$ touch .env

 

Paste the below file (This is production env file)

NODE_ENV = production
PORT = 9000
SECRET_KEY = ‘[some secret, can be a random string]’
API_URL = http://127.0.0.1
HOST = “smtp.gmail.com”
ACCOUNT = “[email acc]”
PASSWORD = “[email acc password]”
GETH_RPC_HOST = ‘http://127.0.0.1:[port for RPC]’
GETH_WS_HOST = ‘http://127.0.0.1:[port for websockets]’
TRACE_CONTRACT_ADDRESS = ‘0x98551206afd3161fe9c8e2383156bdea1b0bb30b’
ANCHORING_CONTRACT_ADDRESS = ‘0xba5C1f68c102Da922E67399E9683114d33C658C3’
MAINNET_RPC = ‘https://ropsten.infura.io/v3/b7067b1ee7c04250bcc6588d8b2595c1’
CHAIN_ID = 3
PRIVATE_KEY = ‘[private key]’
ANCHORING_ENABLE = false
ANCHORING_FREQUENCY = ’24 hrs’
API_LOGGING = false

* Remember to keep secret your SECRET_KEY and PRIVATE_KEY.

TF: to explain some parameters here:

# Mainnet RPC (Infura) for anchoring

MAINNET_RPC = ”

# Chain Id (1 for mainnet, 3 for ropsten testnet)

CHAIN_ID = 3

# Private Key for anchoring wallet

PRIVATE_KEY = ”

# Enable anchoring (true if want to enable otherwise, false)

ANCHORING_ENABLE = true

# Anchoring frequency (Supports: 1 min, 30 mins, 1 hr, 24 hrs, 1 week, 1 month). Please specify the parameters as listed only. By default, it will take 24 hrs.

ANCHORING_FREQUENCY = ’24 hrs’

# Can be true or false. If true, the system will log all API requests.

API_LOGGING = true

 

 

  • Install NPM packages

 

$ npm install

 

TF: with clean Ubuntu install you might experience an error with C compiler similar to what I’ve experienced below (“no acceptable C compiler found in $PATH”):

To solve this, install C compiler:

sudo apt -y install gcc g++ make

And then do the npm install which this time should work (might give some warnings, but should not give any errors).

 

 

  • Start the server

 

$ node app.js

Or

$ pm2 start app.js

Or

$ nodemon app.js

 

TF: similarly as with Geth and IPFS you can run npm via screen, but it’s a better practice to use a manager like pm2 

 

Test that it works

To test it works, open localhost:9000 in the browser (or run “curl localhost:9000” in bash)

 

(you can replace “localhost” with the external IP address of your instance)

 

In the browser you can expect the dashboard login interface to show up like this:

 

Once you see that – congratulations, you have managed to successfully set up a basic node of Dappros Platform (including a private Ethereum blockchain, Node.js application with API layer, MongoDB and IPFS storage).

 

Previous ArticleNext Article
Taras Filatov CEO

Dappros is looking forward to learn about your challenges.
We offer free advice on how blockchain, tokenization & fintech 2.0 can add value to your business.

P.S. I read all inquiries and respond to them personally.

Taras Filatov, PhD Computer Science,
  Dappros Founder & CEO