Dev:Run a Mainnet Node - CLI

From Nexus Wiki
Revision as of 07:45, 4 October 2024 by Nexus wiki (talk | contribs) (Nexus wiki moved page Run a Mainnet Node - CLI to Dev:Run a Mainnet Node - CLI without leaving a redirect)
Jump to navigation Jump to search

This guide is tailored for Debian / Ubuntu distributions.

Prerequisites

  • A computer with a minimum of 1 CPU, 2 GB RAM and 64GB hard disk space, Raspberry Pi 4 with 2 GB RAM with 64 GB SD card.
  • For VPS 1GB RAM is sufficient for normal usage, for dapp backend configuration contact here.
  • Ubuntu server 20.04 LTS or Debian 11 for AMD/IA64 or Ubuntu IOT / Raspberry Pi OS 64 bit for Raspberry Pi.
  • Etcher – To burn the image file to SD card
  • Putty if using SSH via windows.

To install the 5.0.5 stable core, use Ubuntu 20.04 LTS only and the newer versions of Ubuntu, Debian and Raspberry Pi OS( Previously Raspbian) are having issues compiling.

To install the merging / 5.1 branch, it is recommended to install Debian 11 or Ubuntu 20.04. Ubuntu 22.04 will require openssl downgrade to version 1.1.1 to compile successfully.

To build on Raspberry Pi 3 or 4 with 1 GB RAM, enable swap memory with instructions. Proceed after setting up swap.

Prepare The Node

Install ubuntu server 20.04 LTS or distro of choice, install open-ssh server during the install and once the installation is complete restart the node. SSH in node and 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:

sudo ufw allow ssh

Allow API port 8080:

sudo ufw allow 8080/tcp

Allow RPC port 9336:

sudo ufw allow 9336/tcp

Allow mining port 9325, only if connecting a miner:

sudo ufw allow 9325/tcp

Enable firewall:

sudo ufw enable

Check firewall status:

sudo ufw status

Set the node timezone:

sudo dpkg-reconfigure tzdata

To change the hostname – Optional

sudo hostnamectl set-hostname <newhostname>

Reboot node:

sudo reboot

The computer is ready to install the Nexus core.

Compiling Nexus Core

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

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

Download the stable nexus core source code, and should only take a few seconds to complete,

git clone -b 5.0.5 https://github.com/Nexusoft/LLL-TAO

Change into the source code directory

cd LLL-TAO

Clean any previous builds:

make -f makefile.cli clean

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 your CPU. Replace the 1 in ‘j1’to the number of cores / threads for compiling faster.

make -f makefile.cli -j1 AMD64=1

For compiling on Raspberry Pi use:

make -f makefile.cli -j1 ARM64=1

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

Configure the Wallet (nexus.conf)

Create Nexus core data directory (it’s a hidden directory, Nexus daemon creates it automatically on first start. We are creating it manually to create the configuration file. If the directory is already available, skip this step.):

mkdir ~/.Nexus

The wallet configuration is stored in the nexus.conf file, located in the core data directory. Create the nexus.conf file

nano ~/.Nexus/nexus.conf

Copy the below code into the file. Provide a user and password for RPC and API and remove the # in the #stake=1 if you intend to stake.

# This is an example nexus.conf. Tailor it to your deployment.
#RPC credentials, change as needed
rpcuser=<user for RPC>
rpcpassword=<pw for RPC>
#API http authentication credtnials. Change as needed
apiuser=<user for API>
apipassword=<pw for API>
#To run the nexus core as a daemon
daemon=1
#To enable mining with the node, 
#mining=1
#To enable staking
#stake=1

<ipaddress> is IP address of the machine connecting to your node remotely, it may be the interface or dapp server IP address. You can also use '*' wildcard to allow all computers in a particular subnet. llpallowip=192.168.10.*:8080 allows all computers on the 192.168.10 local network.

To access the wallet remotely (from a wallet interface on another machine), add the following lines in the config file:

#To enable RPC remote access
rpcremote=1
#To enable API authentication
apiauth=1
#To enable remote API access. Local API access will be revoked
apiremote=1
# Whitelist IP address for API & RPC
llpallowip=<ipaddress>:8080
llpallowip=<ipaddress>:9336

If testing the merging branch / 5.1:

# To index block data, required to access block data.
indexheight=1
# To index account addresses, required to access the account address.
indexaddress=1

Press Ctrl s and Ctrl x to save and exit the editor.

Bootstrapping Tritium Database

This step will download the nexus database and then extract it to the data folder, alternatively you can skip this step if you choose to synchronise the data from peers which will be slow depending on your internet connection:

cd ~

This will download the database to the home folder. The file is about 5 GB in size:

wget -c http://bootstrap.nexus.io/tritium.tar.gz

This will extract the database to the Nexus core data directory:

tar -xf tritium.tar.gz -C ~/.Nexus

APIs to Control Node

To interact with the nexus core daemon, use API commands via the terminal. Change the location to ~/LLL-TAO folder for the API’s to work. To run the node, stake and transact we will only be using the system, users and finance APIs. If you have any doubts refer to the API documentation here.

Before we start

  • Be careful as the login credentials in the terminal and can be seen by anyone around.
  • Every transaction will need the PIN
  • Every transaction on the Nexus blockchain is a debit to the sending account and credit to the receiving account, two transactions. (This will be useful to understand some API commands)

Change into the LLL-TAO directory to start nexus core (Change to the LLL-TAO folder to run the following commands):

cd LLL-TAO

Start the Daemon

./nexus

Nexus core will be running in the background as a daemon. It will detect peers and synchronize the blockchain. It will take a few minutes to find peers

Stop the Daemon

./nexus system/stop

To Get the Node Info

./nexus system/get/info

The output of the APIs are in JSON format. You can confirm if the node is synchronized by checking the “synchronising”: false and “synccomplete”: 100. Check the block height on the explorer here or here.

After the blockchain is fully synchronized, create a new user account (signature chain).

Username must be a minimum of 2 characters, passwords must be 8 characters and PIN 4 characters. The PIN can be a combination of letters/numbers/symbols.

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

To log into the account (If the account was just created, wait for a few blocks to confirm new account)

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

To unlock the account for staking and automatically credit incoming transactions set (notifications=1). If its not set, then manually credit the incoming transactions else it will be credited back to the sender’s account after 24 hrs. This is the reversible transaction function working as designed.

./nexus users/unlock/user pin= staking=1 notifications=1

To check stake info (works only after login and unlocking for staking).

./nexus finance/get/stakeinfo

To get details of the logged in user accounts and address (trust and default accounts are automatically created with new account):

./nexus users/list/accounts

This will list all the account and its details.

./nexus finance/list/accounts

This will list all transactions sent to a particular genesis or username. It is useful for identifying transactions that need to accept such as credits.

./nexus users/list/notifications

If automatic credit (notifications=1) is not specified as an option with unlock command that will reflect as a pending transaction and will be listed in notifications.

To credit a pending transaction, ‘txid’ is the debit transaction ID from notifications.

./nexus finance/credit/account pin= txid=

To send nexus coins, name is the account to be sent from and name_to is the recipient account, these can be changed to address and address_to.

./nexus finance/debit/account name=username:name/namespace:name amount= name_to=username:name/namespace:name pin=

To check the full Nexus blockchain metrics.

./nexus system/get/metrics

Hope this guide was helpful!