Dev:Build a Nexus Testnet

From Nexus Wiki
Revision as of 01:19, 6 October 2024 by Nexus wiki (talk | contribs)
Jump to navigation Jump to search

This guide will help to set up a standalone nexus tesnet or join the nexus public testnet with mining. Mining is required to produce blocks on testnet as it mimics the mainnet. Testnet mining is very economical as the mining difficulty is very low.

Developers can connect their testnet node to the public testnet, which gives an opportunity to test dapps extensively on testnet before porting to the main net.

To set up a standalone testnet which will mint coins for testing, a minimum of two nodes are required with mining and after some coins are mined, they can be used to add staking to the testnet. The minted coins can be used to test dapps to mimic the mainnet and also distributed test coins to other testers. The two nodes will be set up similarly except for the connect flag in configuration which will refer to each other.

The testnet miner will use the CPU to mine the hash channel. Mining for testnet is very simple, economical and will use only a single worker with a single core CPU to make it as energy efficient as possible.

This guide assumes that each wallet and miner are on one computer, and works with the stable release 5.0.5. The steps below are given for one computer, and will have to be followed on the second one. The next version which is the Tritium++ will have a lot of changes related to API’s, but the setup process is the same.

Prerequisites

Before beginning this guide, check the things needed:

  • Two computers with dual core CPU and 2GB RAM, with a good CPU cooler and case cooling. VPS also can be used.
  • Ubuntu server 20.04 LTS for AMD/IA64 (Use any linux distribution of choice, but this guide is tailored for ubuntu).
  • USB drive or SD card to install ubuntu.
  • Etcher – To burn the OS image file to USB/SD card.

Prepare the Node

Install Ubuntu or distro of choice, Follow the below commands, copy the commands and paste it in the terminal using keys CTRL+SHIFT+v

Update and upgrade the node:

 sudo apt update; sudo apt upgrade -y

Open SSH port before enabling firewall (If using SSH):

 sudo ufw allow ssh

Open ports for API, RPC and mining:

 sudo ufw allow 7080/tcp sudo ufw allow 8336/tcp sudo ufw allow 8325/tcp

Enable firewall:

 sudo ufw enable

Check firewall status:

 sudo ufw status

Set timezone:

 sudo dpkg-reconfigure tzdata

Change the hostname – Not compulsory if already set during the install:

 sudo hostnamectl set-hostname <newhostname>

Reboot node:

 sudo reboot

Compile the Nexus Wallet

Installs the dependencies required for compiling nexus core CLI, It will take some time to complete depending on the internet speed.

 sudo apt-get install -y build-essential libssl-dev libdb-dev libdb++-dev libminiupnpc-dev git

Download the latest nexus core source code, and should only take a few seconds to complete: (The Nexus master branch is linked to the merging branch. For stable build or specific builds refer to the github or contact telegram support).

 git clone --depth 1 https://github.com/Nexusoft/LLL-TAO

Change into the source code directory:

 cd LLL-TAO

Lastly run this command to compile from source. This begins compiling the nexus core, please be patient, as this can take a very long time depending on the CPU. Replace the 1 in ‘j1’to the number of cores / threads for compiling faster:

 make -f makefile.cli -j1 AMD64=1

Will show “Finished building nexus” on a successful compile.

Configure Nexus Wallet

To set up the testnet the wallet needs to be configured properly. The wallet configuration is stored in the Nexus data folder under the user's home directory.

Create the Nexus hidden data folder:

 mkdir ~/.Nexus

Create the nexus.conf file:

 nano nexus.config

Copy the configuration below and change the values to suitable values:

 #Nexus testnet with Miner config- PLEASE CHANGE THESE TO SUITABLE VALUES
 #Set RPC credentials
 rpcuser=<username>
 rpcpassword=<password>
 #Set API credentials
 apiuser=<username>
 apipassword=<password>
 #To enable API authentication for testing
 apiauth=1
 #To enable API remote access
 apiremote=1
 #To enable debug mode
 debug=1
 #To enable the daemon mode
 daemon=1
 #To accept incoming JSON-RPC commands
 server=1
 #User account settings credentials for auto login & auto create. Optionally create, login and unlock directly in the wallet.
 username=<username>
 password=<password>
 pin=<pin>
 autocreate=1
 autologin=1
 #Enable mining
 mining=1
 #Enable Staking
 Stake=1
 #The testnet flag defaults the API port to 7080, RPC to 8336 & mining port to 8325
 testnet=1
 #To connect to the Nexus public testnet. Disable for standalone node
 #connect=node2.nexusoft.io
 #To connect to another node on a local testnet
 #connect=192.168.2.29
 #To run as local node, disable for public node
 nodns=1
 #process notifications (incoming transactions) automatically in background process
 processnotifications=1

To save the config file Ctrl+s & Ctrl+x

Compile the Miner

Install the dependencies (only required if installing miner on a separate computer):

 sudo apt install build-essential libboost-all-dev libdb-dev libdb++-dev libssl-dev libminiupnpc-dev libgmp-dev -y

Clone the NexusMiner repository:

 git clone --branch v1.1 https://github.com/Nexusoft/NexusMiner

Change into the source code folder:

 cd NexusMiner

To precompile the binary use cmake. (cmake version 3.19 or higher only) <pathtosource> is the path to the NexusMiner folder and <pathtobuildfolder> is the path to NexusMiner/build.

 cmake -S <pathtosource> -B <pathtobuildfolder> -DCMAKE_BUILD_TYPE=Release

Change into the prebuilt binaries folder:

 cd build

Compile:

 make

This will create the NexusMiner executable.

Configure the Miner

For the proper functioning of the miner, it needs to be configured; create a configuration file named miner.conf in the same folder as the executable.

 cd NexusMiner/build

Create the miner.conf file:

 nano miner.conf

Copy the miner configuration given below to the file, it uses the JSON format. Change the settings as per needs. Testnet mining will use the port 8325 as default. This config uses four workers, for a testnet just one worker can get the job done.

 {
   "wallet_ip": "127.0.0.1",
   "port": 8325,
   "local_ip": "127.0.0.1",
   "mining_mode": "HASH",
   "connection_retry_interval": 5,
   "get_height_interval": 2,
   "use_pool": false,
   "pool": {
     "username": "Nexus_payout_address_for_pool_mining_only"
   },
   "logfile": "miner.log",
   "stats_printers": [
     {
       "stats_printer": {
         "mode": "console"
       }
     },
     {
       "stats_printer": {
         "mode": "file",
         "filename": "stats.log"
       }
     }
   ],
   "print_statistics_interval": 10,
   "workers": [
     {
       "worker1": {
         "id": "cpu1",
         "mode": {
           "hardware": "cpu"
         }
       },
       "worker2": {
         "id": "cpu2",
         "mode": {
           "hardware": "cpu"
         }
       },
       "worker3": {
         "id": "cpu3",
         "mode": {
           "hardware": "cpu"
         }
       },
       "worker4": {
         "id": "cpu4",
         "mode": {
           "hardware": "cpu"
         }
       }
     }
   ]
 }

Run the Miner

For the miner to mine blocks, a user account is to be created, logged in and unlocked for mining, this also works to bootstrap a new network. Create two separate user accounts for the two nodes.

Start the wallet. Wait for a few minutes for the wallet to be loaded:

 cd LLL-TAO
 ./nexus

If a user account is not configured, auto create and auto login in the wallet configuration, then create an user account, login and unlock for mining. To create a new user account:

 ./nexus users/create/user username=<username> password=<password> pin=<pin>

Login to the user account:

 ./nexus users/login/user username=<username> password=<password> pin=<pin>

Unlock the user account for mining:

 ./nexus users/unlock/user pin=<pin> mining=1 notifications=1

Start the miner:

 cd NexusMiner
 ./NexusMiner

Check the messages the miner prints out, every 10 secs there is a miner statistics printed on the screen (Time set in miner.config). Check for the “Submitting Block ...” and “Block Accepted By Nexus Network”

Stop the miner:

 Ctrl+c

To check the mining information on the wallet:

 ./nexus ledger/get/info

To check the total wallet balance of the logged in user account:

 ./nexus finance/get/balances

To check the account details of the logged in user account:

 ./nexus finance.list/accounts

In account details the newly minted testnet coins are shown in the balance. These can be transferred similar to mainnet coins to other users for testing purposes.