XDC Test Network (Docker)

Follow these steps to create an XDC private network using Docker.

Prerequisites

Install Docker https://docs.docker.com/engine/install/ubuntu/

Git clone https://github.com/XinFinOrg/XDPoSChain.git

Add XDCPay or Metamask browser extension wallets

Steps

Go to the clone directory

cd XDPoSChain

Build the image of docker file (xdc-poschain is the name of the image)

sudo docker build -t "xdc-poschain" -f Dockerfile 

Open your Docker account at https://hub.docker.com/

Create new repository in Docker - (xdposchain)

Name the repository and this name should be public. Go to the Ubuntu terminal and log in to your Docker account

sudo docker login

Docker push <docker-username>/<repository-name>:<tagname>

sudo docker push <docker-username>/xdposchain:latest

If you need to check the Docker images

sudo docker image ls

Create a Docker container

example: -docker run -d -p 8534-8550:8534-8550 -p 30303-30320:30303-30320<docker-username>/<Repository-name>:<tagname> /bin/bash sleep infinity

docker run -d -p 8534-8550:8534-8550 -p 30303-30320:30303-30320 8379817794/xdposchain:latest /bin/bash sleep infinity

Check the Docker container

sudo docker ps -a

Access the latest Docker container

sudo docker start <container ID>

Docker exec command runs a new command in a running container

sudo docker exec -it <container ID> sh

To stop running Docker container (Do not stop it now)

sudo docker stop <container ID>

Create a Genesis File

Use any editor like vi or nano. If you need to install nano use the below command

apk add nano

Run the following command to access and edit the Genesis.json file

vi Genesis.json

The Genesis File contains all the information about the blockchain Network

Note - Add your Metamask Testnet Account address in Genesis.json

Initiate data directory and start the node

XDC --datadir ./myDataDir --identity "Testnet"  init ./Genesis.json
XDC --datadir ./myDataDir --identity "Testnet" --nodiscover --networkid 12 --mine --rpc --rpcaddr "0.0.0.0" --minerthreads 1 --rpcport 8541 --port 30304 --verbosity 5 --etherbase 0x9a085e4591de4aa1a6c92A2d401900C020719b22 console 2>>XDC.log

The node is now running on port 8541. You can add a specific port using <rpcport 8541>

Open a new terminal and open the same container

sudo service docker start
sudo docker start <container ID>
sudo docker exec -it <container ID>

To check that the RPC address is working properly. Curl is needed for this command. If Curl is installed, use this command to install it, otherwise skip to the curl command line.

apk add curl
curl http://localhost:8541

For AWS machines, you need the AWS server public IP.

Example: http://<Server Public IP>:8541/

Adding a custom Network to XDCPay or Metamask

  1. Name - XDC TestNetwork (any)

  2. RPC URL http://<Server Public IP>:8541/

  3. Chain ID - 15 (Used in Genesis.json file)

  4. Currency Symbol - XDC

  5. Click "Save"

Fund the account with testnet XDC

Last updated