Skip to content

Setup a development testnet

This is a guide on setting up a local development testnet (aka devnet) for testing protocol changes or contracts in a live environment. Devnets are short lived in nature and can be reset easily.

This is just a standard haf_api_node deployment with the exception of using the HAF testnet image.

  1. Clone the haf_api_node repository and make a copy of .env file.
Terminal window
git clone https://gitlab.syncad.com/hive/haf_api_node
cd haf_api_node
cp .env.example .env
  1. Locate and modify the following in the .env file:
Terminal window
# required profiles
COMPOSE_PROFILES="core,hafah,servers"
# use the prebuilt testnet HAF image
HAF_IMAGE=registry.gitlab.syncad.com/hive/haf/testnet
# swagger hostname (replace YOUR_HOSTNAME)
PUBLIC_HOSTNAME="YOUR_HOSTNAME"
# caddy sites (read description in the .env file for info)
CADDY_SITES="http://"

Optionally update ZPOOL, TOP_LEVEL_DATASET and ZPOOL_MOUNT_POINT to your desired directory.

  1. Create the folders.
Terminal window
sudo ./create_directories.sh
  1. Copy the config.ini and pgtune.conf files from here into the dataset folder and haf_postgresql_conf.d folder respectively.

Using the default values for example:

  • Directoryhaf-pool
    • Directoryhaf-datadir
      • config.ini
      • Directoryhaf_postgresql_conf.d
        • pgtune.conf
  1. Start the Hive testnet.
Terminal window
docker compose up -d

To reset the Hive testnet, delete the HAF data directory and repeat from step 3 to 5 above.

  1. Clone and compile Magi node executables.
Terminal window
git clone https://github.com/vsc-eco/go-vsc-node
cd go-vsc-node
go mod download
make
  1. Run the devnet setup script. Run -help to view more options.
Terminal window
./build/devnet-setup -db-url 'mongodb://db:27017' -data-dir ./data/devnet -hive-urls 'http://haftestnodeip:80' -nodes 5 -p2p-host /dns4/magi-\? -drop-db
  1. Start all devnet nodes.
Terminal window
# Outside docker: run this for every node
./build/magid -network devnet -data-dir ./data/devnet/data-1
  1. Broadcast the genesis election using one of the instances (shut down the instance’s magid first).
Terminal window
./build/genesis-elector -network devnet -data-dir ./data/devnet/data-5

To reset the Magi testnet, reset the Hive testnet first then repeat step 2 to 4.