Advanced

 

Setting up your QTUM Node

 

While interacting with the QTUM Blockchain it is often much easier to have your very own node. So we will show you how to set up you own QTUM node with Docker and how to communicate with it via RPC.

This type of environment is very useful for people who want to experiment with QTUM either for Staking or and/or develop QTUM smart contracts on the Qtum blockchain.

Prerequisites

 

 
  • Install Docker.

  • VIM (If you are on MAC OS X this should already be present)

For this guide we are using MAC OS X and Qtum Core version mainnet-ignition-v0.15.2 (64-bit)

Step 1: Run Docker

Docker is an open platform that performs operating-system-level virtualization, also known as “containerization”. This system is ideal for creating sandboxed environments.

Make sure you sign into Docker with your username and not your email address

Step 2: Get the QTUM Image from Docker

The first thing we need to do is to build QTUM inside Docker. The QTUM image is already available on Docker Hub which we can pull from the Terminal with a simple command:

docker pull qtum/qtum

Note: Please make sure that you sign in to Docker with your username and not your email address, else you will get the following error:

Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/qtum/qtum/manifests/latest: unauthorized: incorrect username or password

Step 3: Preparing the Configuration File and Data Path

 

The data path is where the QTUM blockchain data is stored and the configuration file is used to set the preferences. We will prepare both on a local directory and then map it into the docker container using the -v command.

In this tutorial we will go to our user directory, i.e Users/your_user/ ,so let’s chose a path to save QTUM blockchain data:

pwd

//Clear any previous data

sudo rm -rf data/qtum-data

//Create the folder

sudo mkdir -p data/qtum-data

//Set the right permissions

sudo chmod a+w data/qtum-data

//Now to check if everything is fine

pwd
ls
cd data
ls

Once this is done, you should see the qtum-data file.

Step 4: Setting up the configuration file

 

We will be setting up the configuration file in VIM, but first we need to make sure we are in the right folder, the /Users/you_user/data.

I usually open a new terminal window when making guides, so you can do the same and get back into the data folder using the cd data command, and to make sure you are in the right folder use the pwd command.

This should display /Users/you_user/data

Now to set up the configuration file enter the following:

vim qtum.conf.

This will create a new configuration file and open vim.

Then tap on i onto the keyboard and paste the following there

rpcuser=test
rpcpassword=test1234
rpcallowip=0.0.0.0/0
rpcbind=0.0.0.0
rpcport=3889
regtest=1

Then press ctrl-c on the keyboard to record the changes. This should show “Type :quit<Enter> to abandon all changes and exit Vim” at the bottom of the terminal.

All the parameters are pretty much self describing except for regtest which allows qtum to start in development mode. For a full detailed configuration file please visit Github and feel free to modify yours as needed. This gives explanations for each parameters mentioned above.

Step 5: Launching the QTUM daemon

 

To launch the QTUM daemon, please open the terminal and type the following:

docker run -d — rm — name qtum_node -p 3889:3889 -v ${PWD}/qtum.conf:/root/.qtum/qtum.conf -v ${PWD}/qtum-data:/root/.qtum/ qtum/qtum qtumd

This is a single command and will launch docker with the QTUM daemon running

To make sure it is running we can check with the following command:

docker ps

This should display the process with the port and name as per image above.

And to stop docker use the following command:

docker stop qtum_node

Step 6: Interacting with the QTUM Command Line

With the QTUM Daemon active we can interact directly through the terminal using the following commands(make sure you stopped the docker first!):

//To shut down the daemon

docker run -d — rm — name qtum_node -p 3889:3889 -v ${PWD}/qtum.conf:/root/.qtum/qtum.conf -v ${PWD}/qtum_data:/root/.qtum/ qtum/qtum qtum-cli stop

//To view the wallet info

docker run -d — rm — name qtum_node -p 3889:3889 -v ${PWD}/qtum.conf:/root/.qtum/qtum.conf -v ${PWD}/qtum_data:/root/.qtum/ qtum/qtum qtum-cli getwalletinfo

//For a full list of commands

docker run -d — rm — name qtum_node -p 3889:3889 -v ${PWD}/qtum.conf:/root/.qtum/qtum.conf -v ${PWD}/qtum_data:/root/.qtum/ qtum/qtum qtum-cli help

Step 7: Interacting via RPC

If you are developing a service and would like to communicate directly with your docker image, you can make calls via RPC.

To make an RPC call, open the terminal, ensure that the qtum docker is running, and type the following.

curl -v — user test:test1234 — data-binary ‘{“jsonrpc”: “1.0”, “id”:”curltest”, “method”: “getinfo”, “params”: [] }’ -H ‘content-type: application/json;’ http://127.0.0.1:3889/

This should return you a json.

Step 8: Entering the Container and Interacting with the QTUM Command Line

Now if you wish to interact from inside the container, open the terminal and type:

docker exec -it qtum_node sh

This should bring you inside the container and you can navigate to the root folder and the QTUM folder by typing:

cd root/.qtum

And to see the list of available commands you can just type qtum-cli help

With this, you complete this workshop successfully!!