SETUP Private Ethereum Network (POA) On Digital Ocean using Puppet.

achinta das
Coinmonks

--

In this post, I will explain an easy way to set up a private eth blockchain on a digital ocean server. Before going to the details we need to understand what is Proof of Authority, I am not going to explain but share a link for details understanding https://www.binance.vision/blockchain/proof-of-authority-explained

I am using Windows 10 system and git bash (Download )https://git-scm.com/downloads

let's start, we are going through step by step process. So in this post, i am going to set up the below list.

  1. Digital Ocean Droplet creates and Install necessary packages for 1 Controller and 3 Nodes.
  2. PoA Network, Ethstats & Explorer

1 . Digital Ocean Droplet Setup: We going to provision 4 droplets on the digital ocean for this tutorial: 3 droplets for Nodes and 1 droplet for Controller. The controller is where we’re going to be doing all the setup using puppeth.

Controller : minimum 1 GBram / 25 GB disk

Node1: 16 GB ram/ 320 GB disk

Node2: 16 GB ram/ 320 GB disk

Node3: 16 GB ram/ 320 GB disk

Controller
Controller Droplet configuration
3 Droplet Same configuration

How to Create Droplet: https://www.digitalocean.com/docs/droplets/how-to/create/. use this link to create a droplet.

Controller Ip : <........>
Node1 Ip: <........>
Node2 Ip: <........>
Node3 Ip: <........>
Node1: I am going to setup stats , explorer.

1.1. Firewall setup: For 3 droplets we need to set up names like Node1, Node2, Node3, and after that need to open port, for that go to Digital Ocean Sidebar, MANAGE-> Networking -> Firewalls -> create a firewall, and set up inbound. Please note all setup for testing POA blockchain setup.

1.2. Prepare The Controller: First, from your local machine, open git bash terminal ssh into the controller droplet:

ssh root@<controller ip> enter then Type Password.

  • Required package installation :
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential bison
  • Install g Version (Go Version Manager)
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)source ~/.gvm/scripts/gvm
  • Go install
$ gvm install go1.4 --binary 
$ gvm use go1.4
$ export GOROOT_BOOTSTRAP=$GOROOT
$ gvm install go1.10.1
$ gvm use go1.10.1
  • Geth clones, build and verify puppet run
$ git clone https://github.com/ethereum/go-ethereum.git 
$ cd go-ethereum
$ make all // if error comes then google "build-essential bison", and install it install properly.
$ cd build/bin
$ ./puppeth
If puppeth runs normally ctrl + C, press to exit
Your Terminal looks like this.
  1. 3. Prepare the Nodes: Open 3 git bash terminal and type droplet IP
1st git bash terminal NODE1 : ssh root@<droplet1 ip>enter , password
2nd git bash terminal NODE2 : ssh root@<droplet2 ip>enter , password
3rd git bash terminal NODE3 : ssh root@<droplet3 ip>enter , password

Run the following command in each terminal (Node1, Node2, and Node3 )

Get the latest package listsudo apt-get update 
sudo apt-get upgrade
Install Docker related packagessudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
Add and verify Docker official GPGcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo apt-key fingerprint 0EBFCD88Add Docker repositorysudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \
stable"
sudo apt-get updateDocker CE, Compose installationsudo apt-get install docker-ce docker-composeAdd Docker Group and Add Current User sudo groupadd Docker
sudo usermod -aG docker $USER
docker ps // if this command run perfectly then your nodes are ready.

Until now if you set up 3 Droplets for nodes and 1 Droplet for the controller and all packages install perfectly then our 50% work done now we can start to work on Ethereum private network. so let's start …….

2. PoA Network: There are some tasks that need to be done before creating a POA network. We need 5 Ethereum accounts, for that we have to create a wallet that can hold the account's details. why do we need that account before set up the network you can get down below. our 1st work was to create a wallet in the controller.

2.1 Wallet

Open git bash and type your controller IP for my case

Log in Controller ssh root@167.71.122.20
password "your password "
Create Wallet Password cd ~
nano passfile // set password inside passfile
sudo perl -pi -e 'chomp if eof' passfile
chmod 700 passfile
Create Account: i am using for loop to create 7 account using geth. for ((n=0;n<7;n++)); do ./go-ethereum/build/bin/geth account new --password ~/passfile; done
Accounts details.

You can see that 7 additional accounts are created, and open the text editor separately to record them. In my case, the following 7 accounts were assigned the same roles as Sealer and Faucet.

Save in text editorpublic address: 0xE214608fAB19971C02f65681B83dD6182b37D98f
Keyfile:UTC--2019-11-25T14-23-51.645631116Z--e214608fab19971c02f65581b83dd6182b37d98f
save all 6 account address like this in text editor .We need Json format key files $ cd ~/.ethereum/keystore
$ cat UTC--2019-11-25T14-23-51.645631116Z--e214608fab19971c02f65581b83dd6182b37d98f // Example
do same things for all 6 key files and save it in text editor so you can use it Sealer 1:
public address: "Your public address
json file : "Your json file "
Sealer 2:
public address: "Your public address
json file : "Your json file "
Sealer 3:public address: "Your public address
json file : "Your json file "
Save like this

Defining POA Network using Puppet

Launch puppeth :  ./go-ethereum/build/bin/puppeth

puppet run screen

+-----------------------------------------------------------+ |Welcome to puppeth, your Ethereum private network manager  |                                                          | This tool lets you create a new Ethereum network down to  |       | the genesis block, bootnodes, miners and ethstats servers |       | without the hassle that it would normally entail.         |       | Puppeth uses SSH to dial in to remote servers, and builds |       | its network components out of Docker containers using the |        | docker-compose toolset.                                   | 
+-----------------------------------------------------------+
Please specify a network name to administer (no spaces or hyphens, please) > poa // name this

Genesis block settings

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)
> 5
Which accounts are allowed to seal? (mandatory at least one)
0xE214608fAB19971C02f65581B83dD6182b37D98f
0x type your public address you save in a editor
//Note: i am using one public addressWhich accounts should be pre-funded? (advisable at least one)
>0xE214608fAB19971C02f65581B83dD6182b37D98f // i am using one
>0X 'Type more then one public address for pre- funding'
Specify your chain/network ID if you want an explicit one (default = random)>
INFO [11-25|14:50:26.561] 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 = poa.json)
> genesis.json
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
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
> 4

Ethstats Settings using puppet

What would you like to deploy? (recommended order)  
1. Ethstats - Network monitoring tool
2. Bootnode - Entry point of the network
3. Sealer - Full node minting new blocks
4. Explorer - Chain analysis webservice (ethash only)
5. Wallet - Browser wallet for quick sends
6. Faucet - Crypto faucet to give away funds
7. Dashboard - Website listing above web-services
> 1
# Choose where to deploy (no list since there are no servers connected yet) choice 1Which server do you want to interact with?
1. Connect another server
> 1
What is the remote server's address ([username[:identity]@]hostname[:port])?
> [ip of Node1]
The authenticity of host '[ip of poa-worker01]:22 ([ip of poa-worker01]:22)' can't be established. SSH key fingerprint is ba:...5e [MD5]Are you sure you want to continue connecting (yes/no)? yesWhich port should ethstats listen on? (default = 80)
> 8080
Allow sharing the port with other services (y/n)? (default = yes)
> n
What should be the secret password for the API? (must not be empty) > api7080#now you can see the magic .
#open the google crome and type http://<ip of Node1>:8080

Deploy Bootnode on Node1

A boot node's only purpose is to help nodes discover each other. Nodes could have dynamic IP, being turned off, and on again. The boot node is usually run on a static IP and thus acts like a pub where nodes know they will find their mates.

What would you like to do? (default = stats)  
1. Show network stats
2. Manage existing genesis
3. Manage tracked machines
4. Manage network components
> 4
#Don't chose 1
1. Tear down Ethstats on [ip of poa-worker01]
2. Deploy new network component
> 2
What would you like to deploy? (recommended order)
1. Ethstats - Network monitoring tool
2. Bootnode - Entry point of the network
3. Sealer - Full node minting new blocks
4. Explorer - Chain analysis webservice (ethash only)
5. Wallet - Browser wallet for quick sends
6. Faucet - Crypto faucet to give away funds
7. Dashboard - Website listing above web-services
> 2
Which server do you want to interact with?
1. [ip of Node1]
2. Connect another server
> 1
Where should data be stored on the remote machine?
> /home/ubuntu/bootnode/
Which TCP/UDP port to listen on? (default = 30303)
> 30306
How many peers to allow connecting? (default = 512)
>
How many light peers to allow connecting? (default = 256)
>
What should the node be called on the stats page?
> poabootnode
#open the google crome and type http://<ip of Node1>:8080
#You can see the bootnode added in ethstats.
# log in Node1 qhbhuji09

Deploy sealer to Node1

Now we are going to deploy sealer to Node1 and same things we have to do for Node2 and Node3 .

#after deployment of boot node you can see down comments list.What would you like to do? (default = stats)  
1. Show network stats
2. Manage existing genesis
3. Manage tracked machines
4. Manage network components
> 4
1. Tear down Ethstats on [ip of Node1]
2. Tear down Bootnode on [ip of Node1]
3. Deploy new network component
> 3
What would you like to deploy? (recommended order)
1. Ethstats - Network monitoring tool
2. Bootnode - Entry point of the network
3. Sealer - Full node minting new blocks
4. Explorer - Chain analysis webservice (ethash only)
5. Wallet - Browser wallet for quick sends
6. Faucet - Crypto faucet to give away funds
7. Dashboard - Website listing above web-services
> 3
Which server do you want to interact with?
1. [ip of Node1]
2. Connect another server
> 1
Where should data be stored on the remote machine?
> /home/ubuntu/sealer
Which TCP/UDP port to listen on? (default = 30303)
> 30307
How many peers to allow connecting? (default = 50)
>
How many light peers to allow connecting? (default = 0)
>
What should the node be called on the stats page?
> "Type any name "
Please paste the signer's key JSON:
> "paste Sealer one Jeson "
What's the unlock password for the account? (won't be echoed)
> "Type password you save in nano file"
What gas limit should empty blocks target (MGas)? (default = 7.500) >What gas limit should full blocks target (MGas)? (default = 10.000) >What gas price should the signer require (GWei)? (default = 1.000)
>
# now see the magic "http://<ip of Node1>:8080"

sealer deployment on poa-worker02, poa-worker03

  • The above procedure should be performed twice, Node2 and Node3 respectively. OutPut down below after completion of Node1, Node2, Node3 sealer setup.
You can see This kind of out put

Create a block

After 3 Nodes setup, you can see some blocks created in <ip of Node1>:8080. but after some time block creation stops.

You must add the Nodes manually with the add Peer command.

Connect to Node1. #open bash terminal $ssh root@<Node1 IP>
$ password
$docker ps
$docker exec -it <put container_id> geth attach ipc:/root/.ethereum/geth.ipc> admin.nodeInfo.enode 
"enode://e21..........@[ip of Node1]: 30307"
> exit
#do same things for Node2 and Node3# save all 3re Node admin.nodeInfo.enode out put
# Node1 : "enode://e21..........@[ip of Node1]: 30307"
# Node2 : "enode://...................................
# Node3 : "enode://...................................
Help: https://github.com/ethereum/go-ethereum/wiki/Connecting-to-the-network

Enter the enode address of the sealnode running at poa-worker02, 03.

#Node1 $docker exec -it <put container_id> geth attach ipc:/root/.ethereum/geth.ipc> admin.addPeer("Node2 enode")
> admin.addPeer("Node3 enode")
> net.peerCount
##Some useful Eth Geth Commands# net.listening
# net.peerCount
# admin.peers
# eth.getBalance(eth.coinbase)
# personal.unlockAccount(eth.coinbase, "password")
# eth.sendTransaction({from:eth.coinbase, to: "address", value: web3.toWei(10, "ether")})

Explorer: Track portfolio for Ethereum address with historical balance charts and transactions, transaction hash , token , Block timing, Account history etc.

# go to controller Launch puppeth :  ./go-ethereum/build/bin/puppeth> poaWhat would you like to do? (default = stats)1. Show network stats2. Manage existing genesis3. Manage tracked machines4. Manage network components> 41. Tear down Sealnode on Node1 Ip
2. Tear down Sealnode on Node2 Ip
3. Tear down Ethstats on Node1 Ip
4. Tear down Bootnode on Node1 Ip
5. Tear down Sealnode on Node3 Ip
9. Deploy new network component
> 9What would you like to deploy? (recommended order)1. Ethstats - Network monitoring tool
2. Bootnode - Entry point of the network
3. Sealer - Full node minting new blocks
4. Explorer - Chain analysis webservice
5. Wallet - Browser wallet for quick sends
6. Faucet - Crypto faucet to give away funds
7. Dashboard - Website listing above web-services
> 4Which server do you want to interact with?1. Node1 Ip
2. Node2 Ip
3. Node3 Ip
4. Connect another server
> 1Which port should the explorer listen on? (default = 80)> 8090Allow sharing the port with other services (y/n)? (default = yes)> nWhere should node data be stored on the remote machine?> /home/ubuntu/explorerWhere should postgres data be stored on the remote machine?> /home/ubuntu/dataWhich TCP/UDP port should the archive node listen on? (default = 30303)> 30309What should the explorer be called on the stats page?> Explorer# now see the magic "http://<ip of Node1>:8090"

Remaining components

There are many more components that can be deployed through puppets. Use and test it by your side.

1. Ethstats  - Network monitoring tool 
2. Bootnode - Entry point of the network
3. Sealer - Full node minting new blocks
4. Explorer - Chain analysis webservice (ethash only)
5. Wallet - Browser wallet for quick sends
6. Faucet - Crypto faucet to give away funds
7. Dashboard - Website listing above web-services

Next, we will connect our eth private blockchain to meta mask and deploy the smart contracts.

Reference

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--