Skip to main content

Install Swaptoshi Core

This document explains how to install swaptoshi-core on your machine using npm.

Pre-Install

To complete the installation certain prerequisites need to be fulfilled. If you have already performed these, then please proceed to the Installation section.

Requirements

Supported Platforms

  • Ubuntu 20.04 (LTS) x86_64
  • Ubuntu 22.04 (LTS) x86_64
  • MacOS x86_64

Node.js

  • 18

The following system requirements are recommended:

Memory

  • Machines with a minimum of 8 GB RAM for the Mainnet.

  • Machines with a minimum of 8 GB RAM for the Testnet.

Storage

  • Machines with a minimum of 40 GB HDD.
note

These recommendations are derived from the log level settings, in the event that the user needs to increase storage to prevent limited memory access and potential memory-related problems with a node. Furthermore, as more transactions are processed and added to the blockchain, the size of the blockchain increases over time and this directly affects the HDD storage requirements for a blockchain node. Hence, adhering to the above listed requirements is highly recommended

Toolchain components

These are used for compiling dependencies.

sudo apt update
sudo apt install -y git libtool automake autoconf curl build-essential python2-minimal

Node.js

Node.js serves as the underlying engine for code execution.

It is recommended to use a Node version manager such as NVM. NVM is a bash script that enables the management of multiple active Node.js versions.

  • Install NVM with the following command shown below:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
info

Please note that you may need to restart your terminal session to use the nvm command.

Alternatively, you can run the following command to use nvm right after executing above installation script:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

Head to NVM official repository to learn more!

  • Install the version 18 of Node.js using NVM with the following command shown below:
nvm install 18
nvm alias default 18
nvm use default

Open Ports

Please ensure, that the necessary ports are open to run Swaptoshi Core as intended.

For example, in case ufw is used on Ubuntu to manage the firewall settings, the respective ports can be opened as follows:

Node P2P communication

ufw allow 7887

Node API

ufw allow 8778

PM2 (optional)

Install PM2 and PM2 Logrotate for managing the start and stop of the application process in the background as shown below:

npm i -g pm2
pm2 install pm2-logrotate
pm2 set pm2-logrotate:max_size 100M

Installation

Install swaptoshi-core globally using npm:

npm install -g swaptoshi-core
info

If you'd like to install swaptoshi-core by building it from source, visit the official GitHub repository for more details.

Run

Create a new file named swaptoshi-core.json, and paste following lines:

{
"name": "swaptoshi-core",
"script": "swaptoshi-core start --api-ipc --network testnet --overwrite-config",
}

Then, use pm2 to start swaptoshi-core instance:

pm2 start swaptoshi-core.json
pm2 logs

use following command to stop all pm2 process, including swaptoshi-core:

pm2 stop all

Post-installation (optional)

Enable IPC & WS in the config and set allowed methods

To make use of all the Swaptoshi Core commands, enable IPC in the config. Config usually located in ~/.klayr/swaptoshi-core/config/config.json:

"rpc": {
// Enable RPC communication over 'ipc' and 'ws'
"modes": ["ipc", "ws"],

// Set allowed methods, or use wild cards "*" to enable all
"allowedMethods": ["generator", "system", "random"],

// In case `modes` include `ws` then, the following port is used
"port": 7887,

// Change to 0.0.0.0 to connect from a remote server
"host": "127.0.0.1"
},

And restart your swaptoshi-core instance. Don't forget to add --overwrite-config flag to start command, for example:

swaptoshi-core start --api-ipc --network testnet --overwrite-config