This blog briefs step by step guide to build a private network in ethereum blockchain using Proof-of-Authority (POA) consensus. For this, we are using separate nodes(wallet) in two different systems and also in addition, we will setup a bootnode. Boot node is used as service discovery node.
For this we need to install Go implementation of Ethereum(Geth) in our system.
Here we use Ubuntu 18.04.3 LTS OS to build this network.
In Ubuntu, one can do it in many ways. The simplest way for installing geth is via PPAs (Personal Package Archives).
To enable launchpad repository:
sudo add-apt-repository -y ppa:ethereum/ethereum
Completing the above we can start installing the stable version of Go Ethereum:
sudo apt-get update
sudo apt-get install ethereum
To find the version of geth, use
:~$ geth version
Geth
Version: 1.9.3-stable
Git Commit: cfbb969da803d4cc92e1a64fc1b3c06db299b564
Architecture: amd64
Protocol Versions: [63]
Network Id: 1
Go Version: go1.11.5
Operating System: linux
GOPATH=
GOROOT=/usr/lib/go-1.11
Now we can start. However, please note that this guide is only meant for testing, not for any industrial purpose.
First, create a working environment in one system - Peer1
$ mkdir pnet
cd pnet
pnet$ mkdir node1
Also set up another working environment in 2nd system - Peer2
$ mkdir pnet
cd pnet
pnet$ mkdir node2
Now start creating an account (wallet). This wallet holds the users public and private key which is required for interacting with the blockchain. Each node in the network must be able to sign a transaction using their available private key. Therefore we need at least two accounts,
For the node1( In the peer1):
pnet$ geth --datadir node1/ account new
INFO [09-17|10:34:07.533] Maximum peer count ETH=50 LES=0 total=50
INFO [09-17|10:34:07.533] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:
For the node2(in the peer2):
pnet$ geth --datadir node2/ account new
INFO [09-17|10:39:39.283] Maximum peer count ETH=50 LES=0 total=50
INFO [09-17|10:39:39.283] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:
This will create a public address. You need to store this public address safely for future reference. Kindly copy and safe this address directory.
Peer1:
pnet$ echo '95491f49d86d68ab43f55db5b6679b4d90f1ea84' >> accounts.txt
Peer2 :
pnet$ echo 'ae69ea23a63ac199d336c57031308a206d01159c' >> accounts.txt
Also, save the password to txt file in the same directory of each node. This will easily unlock the wallet.
Peer1:
pnet$ echo 'pwdnode1' > node1/password.txt
Peer2 :
pnet$ echo 'pwdnode2' > node1/password.txt
Create a Genesis file:
Genesis file is the first file to initialize the blockchain. Genesis block is the first block in the blockchain and is crafted based on the parameters in the genesis.json file. Geth has many executables such as boot node, puppeth and many more. Puppeth helps to create genesis file from scratch.
Start puppeth :
pnet$ puppeth
Please specify a network name to administer (no spaces, hyphens or capital letters please)
> pnet
Sweet, you can set this via --network=pnet next time!
INFO [09-17|11:43:03.307] Administering Ethereum network name=pnet
WARN [09-17|11:43:03.367] No previous configurations found path=/home/pnet/.puppeth/pnet
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
What would you like to do? (default = create)
1. Create new genesis from scratch
2. Import already existing genesis
> 1
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)
> 3
Which accounts are allowed to seal? (mandatory at least one)
> 0x95491f49d86d68ab43f55db5b6679b4d90f1ea84
> 0x
Which accounts should be pre-funded? (advisable at least one)
> 0x95491f49d86d68ab43f55db5b6679b4d90f1ea84
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
> yes
Specify your chain/network ID if you want an explicit one (default = random)
> 7410
INFO [09-20|10:07:39.675] 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 configurations
2. Export genesis configurations
3. Remove genesis configuration
> 2
Which folder to save the genesis specs into? (default = current)
Will create pnet.json, pnet-aleth.json, pnet-harmony.json, pnet-parity.json
>
INFO [09-20|10:07:58.879] Saved native genesis chain spec path=pnet.json
ERROR[09-20|10:07:58.879] Failed to create Aleth chain spec err="unsupported consensus engine"
ERROR[09-20|10:07:58.915] Failed to create Parity chain spec err="unsupported consensus engine"
INFO [09-20|10:07:58.916] Saved genesis chain spec client=harmony path=pnet-harmony.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
> ^C // Ctrl+c to exit
Initialize your node
Now we can initialize our node with genesis file we have created.
pnet$ geth --datadir node1/ init pnet.json //initialize it with genesis.json we have created.
Start geth console.
geth --port 3010 --networkid 5801 --datadir=./node1 --maxpeers=50 --rpc --rpcport 7410 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --allow-insecure-unlock console 2>>eth.log
This will start geth console
instance: Geth/v1.9.3-stable-cfbb969d/linux-amd64/go1.11.5
coinbase: 0x95491f49d86d68ab43f55db5b6679b4d90f1ea84
at block: 0 (Fri, 20 Sep 2019 10:06:59 IST)
datadir: /home/cybrosys/Work/devnet/node1
modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> eth.coinbase
"0x95491f49d86d68ab43f55db5b6679b4d90f1ea84"
You can unlock your account by :
>personal.unlockAccount(eth.coinbase,”yourpassword”,9999999)
Now start creating new account from the current node1:
>personal.newAccount(“yourpassword”)
"0x99316969752a421b5ddc6e04b17274c2fd0d22a7"
If we want to do any action regarding this account we need to unlock that account first.
>personal.unlockAccount(eth.accounts[1],”yourpassword”,9999999)
Check your peer balance by:
> eth.getBalance(eth.coinbase)
9.046256971665327767466483203803742801036717552003169065582623750618213253
This is because we have pre-funded in puppeth
> eth.getBalance(eth.accounts[1])
0
Since account[1] has no balance, do some transactions:
>web3.eth.sendTransaction({from:eth.coinbase,to:eth.accounts[1],value:web3.toWei(300,"ether")})
"0xfce0e4b502691995c025c7980ac8a1b77592b96fd474e2bc6ee51a6504716fb3"
After this, start mining for the new block.
>miner.start()
null
Now check the account[1] balance:
> eth.getBalance(eth.accounts[1])
300000000000000000000
New block will get added every 3 seconds automatically. Let’s use tail to open this file in console.
$ tail -f eth.log
How to connect Multiple node to the POA network:
Let's see how node2 from peer2 can connect to the network.
Firstly we need to add any node to genesis config. We can do this by:
geth --datadir node2 init pnet.json
After this start geth console of node2.

Node1 geth console
geth --port 3012 --networkid 7410 --datadir=./blkchain --maxpeers=5 --rpc --rpcport 8542 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --allow-insecure-unlock console 2>>eth.log
To connect node2, we need to know the enode of node1.

Node1 geth console
Note the ip address mentioned in enode. It may not be the same as the actual IP. Need to change it to local connection. Check your connection and change it accordingly.
On node2 geth console add peers using admin.addPeer.
>admin.addPeer('enode://d74ad5aebb42d2042c2d490712b2d87116aefc90a309ffdb23006c0b9d7dcbef6c6af01660d0d907070ca988934ab18649216e509edc9b7eb660ac17e7ab9ea6@127.0.1.0:3010')
true
Now we can check whether node2 is connected or not by going to node1 geth console and:

Node1 geth console
Now the node2 is connected to the chain. Now we can do a test transaction by simply transferring some ether from node1 to node2.
Set your etherbase:
>miner.setEtherbase('your address')
True
And do transaction:
>web3.eth.sendTransaction({from:eth.coinbase,to:’e4cbddc5b6b108046e1b2a17124d43f21abddbd4’,value:web3.toWei(300,”ether”)})
Check the balance of node2.
Now it's time to develop our own DAPP on ethereum private network and do transaction.