Introduction

Here, we’ll installing and running a local instance of Quai Network in a containerized environment. The local network instance contains one full node, one CPU miner for each of the 9 shards, and multiple accounts with pre-loaded Quai and Qi balance. The containerized local network instance is designed to provide an easily configurable, low overhead development environment for builders.

Install Dependencies

To run a local instance of Quai Network, you’ll need to install a few dependencies.

1

Install Docker Compose

There are two methods to install Docker Compose:

  1. Install Docker Desktop, which bundles Docker Compose. (recommended)
  2. Install the Docker Compose plugin via CLI.

If you’re unsure which method is best for you, visit the Installing Docker Compose page for more information.

2

Install Local Node Runner

To install the Local Node Runner, you’ll need to clone the quai-local-node repository and navigate to it.

git clone https://github.com/dominant-strategies/quai-local-node
cd quai-local-node

Run Local Instance

Now that we’ve installed Docker Compose and navigated to the quai-local-node repository, we can run the local network instance.

Start

To start the local network instance in a Docker container, run:

bash docker-compose up -d

After running this command, you’ll see each of the processes start up. One go-quai container, and 9 instances of quai-cpu-miner (one for each shard) should initialize like so:

[+] Running 10/10
 ⠿ Container quai-local-node-paxos2-quai-cpu-miner-1   Started
 ⠿ Container quai-local-node-cyprus1-quai-cpu-miner-1  Started
 ⠿ Container quai-local-node-cyprus2-quai-cpu-miner-1  Started
 ⠿ Container quai-local-node-hydra2-quai-cpu-miner-1   Started
 ⠿ Container quai-local-node-paxos1-quai-cpu-miner-1   Started
 ⠿ Container quai-local-node-cyprus3-quai-cpu-miner-1  Started
 ⠿ Container quai-local-node-go-quai-1                 Started
 ⠿ Container quai-local-node-paxos3-quai-cpu-miner-1   Started
 ⠿ Container quai-local-node-hydra1-quai-cpu-miner-1   Started
 ⠿ Container quai-local-node-hydra3-quai-cpu-miner-1   Started

View Logs

To view the logs for the go-quai container from your terminal, run:

## print global logs
docker logs quai-local-node-go-quai-1

## follow global logs
docker logs -f --tail 0 quai-local-node-go-quai-1

If you’d like to access logs for a specific shard, you’ll need to navigate to the quai-local-node-go-quai-1 container and print logs directly.

## navigate to go-quai container
docker exec -it quai-local-node-go-quai-1 sh

## follow logs for a specific zone
tail -f nodelogs/zone-0-0.log

## follow logs for a specific region
tail -f nodelogs/region-1.log

Stop

If your local network instance is running in the background, run the following command to stop:

docker-compose down

If your local network instance is running in the foreground, you can exit the terminal or use CTRL+C to stop the container.

Custom Network Configuration

The below configuration section is only necessary for running non-default configurations. If you only want to run the default network configuration of 9 slices and miners, you can skip this section.

The quai-local-node is configured to run all 9 shards (slices) and a CPU miner for each shard by default. It is recommended to run the default configuration for most use-cases. If you want to run a custom slice configuration, the section below details how to do so.

To alter the default local network configuration, you’ll need to:

  • Edit the slices the local node is running in the config.toml file
  • Edit the number of CPU miners to match the number of shards in the docker-compose.yml file
1

Configure Slices

To start slice configuration, open the node config file with a text editor:

vim config/go-quai/config.toml

Inside of this directory is the config.toml file. The config file has a slices variable with a default value of all 9 slices.

slices = '[0 0],[0 1],[0 2],[1 0],[1 1],[1 2],[2 0],[2 1],[2 2]'

Edit the slices variable to match the number of shards you want to run. For example, if you want to run 3 shards, you could set the slices variable to [0 0],[0 1],[0 2].

2

Configure CPU Miners

To edit the CPU miner config, you’ll need to edit the docker-compose.yml file. Open the docker-compose.yml file with a text editor:

vim docker-compose.yml

Each of the miner instances in the config file has a replica variable that defaults to 1. If this value is set to 1, a miner for that chain will be spun up on start, if the value is set to 0 the miner will not be spun up on start.

cyprus1-quai-cpu-miner:
  image: quainetwork/quai-cpu-miner:0.1.0-test.4
  volumes:
    - ./config/quai-cpu-miner/cyprus1-config.yaml:/root/config/config.yaml
  deploy:
    resources:
      limits:
        cpus: '1'
    replicas: 1
  command: ['./build/bin/quai-cpu-miner']
  networks:
    - quainet

We need to ensure that a CPU miner is spun up (replica is set to 1) for each of the slices we configured in the node above. For example, if we’re running slices [0 0],[0 1],[0 2], we need to set the replica value for the cyprus1, cyprus2, and cyprus3 miners to 1 and all the others to 0.

cyprus1-quai-cpu-miner:
  ...
  replicas: 1

cyprus2-quai-cpu-miner:
  ...
  replicas: 1

cyprus3-quai-cpu-miner:
  ...
  replicas: 1

paxos1-quai-cpu-miner:
  ...
  replicas: 0

etc...

After matching the slices the node is running to the CPU miner configurations, you can start up your custom local network instance.

Interacting With The Local Network

To interact with the local network instance, you can use the Quais SDK or JSON RPC API. The network is accesible via specific networking ports on localhost.

ShardHTTP PortWS Port
Prime90018001
Cyprus90028002
Paxos90038003
Hydra90048004
Cyprus 192008200
Cyprus 292018201
Cyprus 392028202
Paxos 192208220
Paxos 292218221
Paxos 392228222
Hydra 192408240
Hydra 292418241
Hydra 392428242

SDK

You can use the Quais SDK to create a provider connected to your local network instance and get chain data and send transactions.

import { quais } from 'quais'

// create local provider
const provider = new quais.JsonRpcProvider('http://localhost')

// get block number on cyprus 1
const currentBlock = await provider.getBlockNumber('Cyprus1')

JSON RPC API

You can make requests to your local network using the JSON RPC API and cURL:

# get paxos 3 gas price
curl --request POST \
  --url http://localhost:9222 \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "method": "quai_gasPrice",
  "params": [],
  "id": 1
}'

Accounts

The local network we just spun up starts with a number of accounts pre-loaded with Quai and Qi tokens for each shard. A full list of accounts with pre-loaded balances, sorted by shard and ledger, can be found in the genallocs directory of the quai-local-node repository.

These accounts are for local testing purposes and should not be used in any production environment. They are not secure and should only be used for testing.

For quick reference, 1 account for each shard and ledger can be found below:

Quai Accounts

ShardAddressPrivate KeyBalance
Cyprus10x000001273B55E9e5998328216dB1b130c231221C0xb3c87ca9645adcf75be5c4d6609fd257f897fd53849c7ecca81acae9966a6ec010000 Quai
Cyprus20x010001D025371794a6eDb5feE8aC2F384EdD74630xcea8ebb619f8e4ea11ee75cb72221a6f39591a99d7cf688de9f30832809fb75110000 Quai
Cyprus30x02000415996A1B0cFF4b2FD078c779cF6C3E9AaC0xfc86fae56f462d2ae43bca8f819b1137c9e3150ba3ff79d4d5068b6e39c1c97510000 Quai
Paxos10x10000197Ec7c3e6ce4D9a832c0641528c5e268A60x01d872f0bc5f94490c2ed9026d58a116656dcb3c997f42062d01799e5b45806210000 Quai
Paxos20x11000207A6723c18085c12F50F62929bb78932c40x1d7a3a668ac8b20bf538a6d1060de043f10b1db5f1df2140fa0e8d479820e76310000 Quai
Paxos30x120000833E752B14A00eBB2c00eF0FD7C90C21230xc0061e94c526e7d9d97a2874f129e72e4f821a8f78ca2fd8198c005bc14e2a9210000 Quai
Hydra10x2000011eCb5FDEA6Eb074cbe60b6Ad372948d99a0xc77fb4c5b1612f702ef097561f75ee5876987ef547977020a86528fbc9f7bbbc10000 Quai
Hydra20x2100042dEf9D880e029Ca948f97C180c202bd7430x44af4c54c44d96bbf3d9c602967822246381d2287fe544fd5480d05b25b80bb910000 Quai
Hydra30x2200035A5A89846AD708d8732B6c85dFAbE354890x8cd878d69b1b848b3c98c623e4e56e3b0ed1035984f6f721a99ef716637e338210000 Quai

Qi Accounts

ShardAddressPrivate KeyBalance
Cyprus10x0080038f1C9a96b196914939301F9a46d7E27e7E0x5b18d340e2e5172a90dfcc43c800519cf4a77b82750b8964b3f421dc929eac53100000 Qi
Cyprus20x01800Daf0f10f7d0CceF2B77893d5a7f86D6D4060x4500c9cef91ac29479cf50a00c49d27ba14e84df83b8e332db34fa1cbdd799b7100000 Qi
Cyprus30x02800a7c404409166D903Dd3421595112f1DaF4D0xbc144acdd4d53488e4005d404f42450a879eb1015a6f4bbf80956b4810b5a068100000 Qi
Paxos10x1080049337283F6c3aDfD535835258a03CF2b9210x511930ce12cbf86325eb2652459b6a47b75ddc892a09549f094f0011062a11f4100000 Qi
Paxos20x1180008531658Aa78161D00689267725C771aD3d0x89086104efd789c7de9ee69beb44ad70818a772a90b6d3f3ec26da930a47a2da100000 Qi
Paxos30x12800163E05c66e107864D9c18067468cf79990f0xa7995e0942e6510a2fd3461c0dbe081fc8e79c6e891fd2fcde5897e41700789a100000 Qi
Hydra10x208000B3ED3a21D2018E72533D55679760C7a8d20x36f009591733e706085ba4b6c3c6bbc8e35fa5e9f075979650523c18f18dacec100000 Qi
Hydra20x218000a39174Db63f0047DC571CB2279d6D294340xf07d9c6d2ee5cd1f5661d87afea21cd21e4a52ff1ea4851b7507b4ef673c4311100000 Qi
Hydra30x228003fD91A5B55dBAfc95384e3A8DBf30B21AA80x2c1b28175b12d8fdeb8355918fcb7492fcbc7b118ecf301cd928477815084312100000 Qi