Build a Quorum network from scratch

By Aleenajoe | Cryptosign | 7 Feb 2020


The Quorum network construction procedure is on the official website, but understanding the procedure requires a separate understanding of Ethereum.

This article briefly describes each command, and we have made it so that you can understand the construction of the Quorum network before learning Ethereum.

Quorum offers three consensus algorithms: Raft, IBFT, and PoA . This time, we will build using the simplest Raft.

By learning through this article, you will be able to create a Quorum network from scratch.

References: Quorum official documentation

The whole procedure

  1. Preparation of Quorum
  2. Describe Node settings
  3. Node startup and operation check

Preparation of Quorum

To build a Quorum network, you need to install tools such as Geth that support Quorum.

First, install and build Quorum.

Install Quorum

git clone https://github.com/jpmorganchase/quorum.git

Build Quorum

$ Whose CD
$ make all

Pass the Quorum pass

Pass the path to the script that launches Quorum.

 $ export PATH=$(pwd)/build/bin:$PATH

Node settings

Node is one machine that participates in the Quorum network.
To build a Node, create the following:

  1. Node working directory
  2. Account that manages Node
  3. Genesis file describing the initial state of the blockchain
  4. Creating a key (nodekey) that identifies a node
  5. Create static-nodes.json configuration file for nodes participating in the network

Let's look at each step.

Creating a working directory for Node

Let's create a working directory called new-node-1.
This directory will store node information.

$ mkdir fromscratch
$ cd fromscratch
$ mkdir new-node-1

Create Node Management Account

Create an account owned by Node with the following command.

You will be prompted to enter a passphrase. Enter any passphrase. This passphrase is important and should be saved and not lost.

$ geth --datadir new-node-1 account new
INFO [12-18|14:51:17.224] Maximum peer count                       ETH=25 LES=0 total=25
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {0431a975ebfade62caaa86d3a38eb087837ee222}

Let's confirm that the account was created with the following command.

$ ls new-node-1/keystore/
UTC - 2019-12-18T05-51-19.943010000Z - 0431a975ebfade62caaa86d3a38eb087837ee222

The part of the number string (0431a ... in the above example) displayed by this command is the account address of the administrative account, which will be used later.

$ touch genesis.json

Copy and paste the following genesis.json file and rewrite the address part.
The alloc key sets the initial balance for the account.

 

{
  "alloc": {    
    // replace 0x with actual address
    "0x0431a975ebfade62caaa86d3a38eb087837ee222": {
      "balance": "1000000000000000000000000000"
    }   
},
 "coinbase": "0x0000000000000000000000000000000000000000",
 "config": {
   "homesteadBlock": 0,
   "byzantiumBlock": 0,
   "chainId": 10,
   "eip150Block": 0,
   "eip155Block": 0,
   "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
   "eip158Block": 0,
   "isQuorum": true
  },
 "difficulty": "0x0",
 "extraData": "0x000000000000000000000000000000000000000000000000000000000000",
 "gasLimit": "0xE0000000",
 "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
 "nonce": "0x0",
 "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "timestamp": "0x00"
}

Create Node Key

Node Key is a key to identify a node and is used as an ID.

Let's create a Node Key using the bootnode command.
Save the key you created in your working directory.

$ bootnode --genkey = nodekey
$ cp nodekey new-node-1/  

Let's check the Node ID with the following command.

$ bootnode --nodekey=new-node-1/nodekey --writeaddress > new-node-1/enode
$ cat new-node-1/enode
77822727e5b6254c7061e03846250e1ffdbe6f0be1f9f849a1756ff7dc8264455dcce504f7bb42c5d7a12bc940a32890e031c4e719ee5f2bd3347d27015edb22

Here, enode is an abbreviation of "ethereum node", and what is displayed is the address that is the enode ID.

Create static-nodes.json

static-nodes.json is a file that describes a list of nodes that have initially joined the private network.
Nodes not described here need to be added to the network using separate commands.
This time, there is only one node, so write your own settings.

First, create a static-node.json file.

$ vim static-nodes.json
... Please create a file with the following contents.
[
  // Replace 778 .... edb22 before the @ mark with the actual address
  "enode://77822727e5b6254c7061e03846250e1ffdbe6f0be1f9f849a1756ff7dc8264455[email protected]127.0.0.1:21000?discport=0&raftport=50000"
] 

Next, copy the files to your working directory.

$ cp static-nodes.json new-node-1

You are now ready to start the node.

Starting a node

Start the node based on the settings created in the previous steps.
* Note If the path does not pass once, such as closing the console, it will fail. If it fails, execute export PATH = $ (pwd) / build / bin: $ PATH again in the quorum directory.

Node initialization

First, initialize based on the node settings.

$ geth --datadir new-node-1 init genesis.json

Starting a node

Write the start script of Node.

$ vim startnode1.sh
... Describe the file with the following contents. 
#!/bin/bash
PRIVATE_CONFIG=ignore nohup geth --datadir new-node-1 --nodiscover --verbosity 5 --networkid 31337 --raft --raftport 50000 --rpc --rpcaddr 0.0.0.0 --rpcport 22000 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,raft --emitcheckpoints --port 21000 >> node.log 2>&1 &

Make the startup script executable and execute it.

$ chmod +x startnode1.sh 
$ ./startnode1.sh

This completes the startup of the node.

 

Connecting to a node

Now that the node is up, let's connect to the network.
Using geth, you can connect to the network with the following command.

 

$ geth attach new-node-1/geth.ipc
Welcome to the Geth JavaScript console!

instance: Geth/v1.8.18-stable-b1f3b96e(quorum-v2.4.0)/darwin-amd64/go1.13
coinbase: 0x0431a975ebfade62caaa86d3a38eb087837ee222
at block: 0 (Thu, 01 Jan 1970 09:00:00 JST)
 datadir: /Users/admin/WebstormProjects/quorum-gs/quorum/fromscratch/new-node-1
 modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 raft:1.0 rpc:1.0 txpool:1.0 web3:1.0

Execute the command and check the status.

> raft.cluster

[{
    hostname: "127.0.0.1",
    nodeId: "77822727e5b6254c7061e03846250e1ffdbe6f0be1f9f849a1756ff7dc8264455dcce504f7bb42c5d7a12bc940a32890e031c4e719ee5f2bd3347d27015edb22",
    p2pPort: 21000,
    raftId: 1,
    raftPort: 50000,
    role: "minter"
}]
> 

Conclusion

This is the Quorum network construction procedure.

To use Quorum for production, it is necessary to build a network with multiple nodes.
In such a case, it is necessary to build a node on another PC, share the configuration file, and make settings so that the network can be connected to each other.

BaaS, such as the Azure Blockchain Service, enables such troublesome settings in minutes.

How do you rate this article?

0



Cryptosign
Cryptosign

Crypto/Blockchain education/news//articles and ....etc i hope you enjoy my content

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.