Developers Forum for XinFin XDC Network

Cover image for How to Set Up a Private Blockchain Network with XDC Network Codebase.
daniel weber
daniel weber

Posted on

How to Set Up a Private Blockchain Network with XDC Network Codebase.

Today, more enterprises seek to set up private networks based on the XDC Network codebase. Whilst the process may seem daunting, knowing the steps to follow simplifies the process.

As such, we’ve decided to give you a helping hand. Through this step-by-step guide, you’ll learn how to set up a private network on the XDC Network codebase.

Note: This article walks you through the step-by-step setup of a XinFin private network with three masternodes (or network nodes). However, you can set up a private network with up to 5000 Nodes.

Setting Up Private Blockchain Network Using XDC Network Codebase.

1. Install Golang
Download and install Golang via these steps:

i) Download the Go installer for Windows, Linux, or Mac.

ii) Install Go on your computer system by following the specified steps, and you’re set up.

For more information, refer to the GO installation page.

2. Set Environment Variables
i) set GOROOT=$HOME/usr/local/go

ii) set GOPATH=$HOME/go

3. Prepare XinFin Network Client Software
Download the source code and build here.

Run the commands:

i) git clone 
ii) git checkout v1.4.4
iii) make all
Enter fullscreen mode Exit fullscreen mode

Customize Genesis Block Using the Puppeth Tool

Run Puppeth command and answer questions about your private chain as follows:

Enter fullscreen mode Exit fullscreen mode

i) Set chain name as XDPoS
Image description

ii) Enter 2 to configure new genesis
Image description

iii) Enter 3 to select XDPoS — delegated-proof-of-stake consensus
Image description

iv) Set blocktime (default 2 seconds)
Image description

v) Set a reward for each epoch
Image description

vi) Set addresses to be initial masternodes
Image description

vii) Enter the signers address.
Image description

viii) Set the number of blocks of each epoch (default 900).
(Note: If you would like to customize the epoch number, update the code here: common/constants.go:14 EpocBlockRandomize = 900)
Image description

ix) Set gap
(That is: How many blocks are needed to prepare a new masternodes set before checkpoint?)
The suggested gap = 5

Image description

x) Enter the foundation address in which you hold the private key
Image description

xi) Enter accounts with which you control private keys to unlock the MultiSig wallet
Image description

xii) Enter how many Foundation MultiSignWallet require to confirm tx default=2
Image description

xiii) Enter the accounts that are allowed to confirm in Team MultiSignWallet
Image description

xv) Enter the number of Team MultiSignWallet that are required for confirming tx in MultisignWallet (default=2)
Image description

xvi) Enter swap wallet address for fund 55 million XDC
Image description

xvii) Enter the address which needs to be prefunded
Image description

xviii) Enter the network ID
Image description

xix) Export the genesis file by:

  1. Selecting 2 to manage existing genesis.
  2. Selecting 2 to export genesis configuration
  3. Enter genesis filename — -XDPOS.json Image description

xx) Press Control(CtrL) + C to exit.

5. Setup Bootnode
i) Initialize bootnode key by entering the command:

./bootnode -genkey bootnode.key
Enter fullscreen mode Exit fullscreen mode

ii) Then start bootnode with the command:

./bootnode -nodekey ./bootnode.key
Enter fullscreen mode Exit fullscreen mode

iii) Copy bootnode information shown:

Enter fullscreen mode Exit fullscreen mode

Image description

6. Start the Masternode

Follow the following steps to start the masternode:

i). Clone the Local DPoS Setup repository from:

ii). Replace the genesis file with yours.

iii). Enter the bootnode key.

iv). Edit the file by changing the network id and replacing the enode which was generated earlier.

v). Enter the private key of the 3 masternode in the .env file, the masternode, and signers private key which was mentioned in the genesis file.

vi). Start your masternode with the command :

Enter fullscreen mode Exit fullscreen mode

To help you understand flags in the file, here are several explanations.
i). Verbosity — — The log level ranges from 1 to 5. And, in this case, we’re using 4 for debug messages

ii). Datadir — -That’s the path to your data directory created above.

iii). Keystore — -That’s the path to your account’s Keystore created above.

iv). Identity — -That’s your full node’s name.

v). Password — -That’s your account’s password.

vi). Networkid — -This is XinFin’s testnet network ID.

vii) Port — -Your enterprise’s full node’s listening port (default to 30303)

viii). rpc, — rpccorsdomain, — rpcaddr, — rpcport, — rpcvhosts — -Your full-node will accept RPC requests at 8545 TCP.

ix). ws, — wsaddr, — wsport, — wsorigins — -Your full-node will accept Websocket requests at 8546 TCP.

x). Mine — — It implies that your full-node wants to register to be a candidate for masternode selection.

xi). Gasprice — -That’s the minimal gas price to accept for mining a transaction.

xii). Targetgaslimit — — Target gas limit sets the artificial target gas floor for the blocks to mine (default: 4712388)

xiii). Bootnode — — Bootnode information helps in the discovery of other nodes in the network

xv). Gcmode — — That’s blockchain’s garbage collection mode (“full”, “archive”)

And, to see all flags usages, use the command: XDC — — help

7. Check Your Private Chain
To check whether your chain passes the first checkpoint, follow the following steps.

i). Connect rpc



ii) Verify Checkpoints.

iii) Wait for 30 minutes to see if your chain passes the first checkpoint.

Useful Tools to adopt:
Some tools you can use to run different functions of the private blockchain network include:

i). XDCPay
This extension helps access XDC’s XDPoS enabled distributed applications or “Dapps” within your browser. With the extension, you inject XDC’s XDPoS web3 API into every website’s javascript context, helping Dapps read from the blockchain.

ii) XDC Remix
With the web browser-based integrated development environment, you can write, compile, deploy, and run Solidity-based smart contracts on the XDC network.

For technical support, let’s connect via XDC’s Social media communities on Slack, Twitter, and Discord and XDC Forum.

Originally published on Hackernoon

Discussion (0)