NPM setup

Pre-installation

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[1].

Create a new user

To run and manage a Klayr Core node in the future, please create a separate klayr user as described below:

  • Ubuntu

  • MacOS

The klayr user itself does not need any sudo rights to run the Klayr Core.

sudo adduser klayr

The above command will create a new user.

It is not necessarily required to set up a klayr user, especially when you are running a local instance for development purposes.

However, if it is required then it is recommended to create the user using the MacOS GUI.

Toolchain components

These are used for compiling dependencies.

  • Ubuntu

  • MacOS

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

Ensure that both XCode and Homebrew are installed.

brew install autoconf automake libtool python2

Node.js & NPM

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

  • Option A - Node version manager

  • Option B - Node.js package

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.

  1. Install NVM and follow the official instructions here.

  2. Install the latest LTS version of Node.js using NVM with the following command shown below:

nvm install 18

If NVM or other package managers are not required, it is possible to install the Node package globally as shown in the following commands below:

Ubuntu

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

MacOS

For MacOS, please execute the following command below:

brew install node@18

In case you experience any permission issues, please follow the instructions below to adjust the location of the global NPM packages:

  1. On the command line, in your home directory, create a directory for global installations:

    mkdir ~/.npm-global
  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'
  3. In your preferred text editor, open or create a ~/.profile file and add the following line:

    export PATH=~/.npm-global/bin:$PATH
  4. On the command line, update your system variables:

    source ~/.profile

Open ports

Please ensure, that the necessary ports are open to run Klayr 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:

8778 and 7887 are the default ports. If you configured custom ports in the node config file, adjust the examples to these specific ports.
Node P2P communication
ufw allow 7887
Node API
ufw allow 8778

Installation

Install Klayr Core with NPM:

npm install --global klayr-core

Location

Klayr Core will be installed under the installation path of NPM.

To check the location where Klayr Core was installed, execute the following:

npm list --global --depth=0

Start

After successful installation, start the node with the following command:

  • Mainnet

  • Testnet

  • Devnet

klayr-core start --network mainnet

The default log levels for Mainnet are:

"logger": {
    "fileLogLevel": "error",
    "consoleLogLevel": "none"
},

So if you start the node, it won’t show any logs in the console. This is the recommended setting for reducing the number of logs for a running node. However, to verify that the node started correctly, update the log levels in the config to info or lower.

Alternatively, start the node with the following flag:

klayr-core start --network mainnet --console-log=info

See the Managing logs guide for more information about logging.

klayr-core start --network testnet
klayr-core start --network devnet
The passphrase for the genesis account(s) can be found here in the Klayr Core GitHub repository under the following path: config/devnet/passphrase.json.

Post-installation (optional)

Use pm2 to run Klayr Core in the background

It is recommended to use a process manager such as PM2 to run Klayr Core in the background.

Enable IPC & WS in the config

To make use of all the Klayr Core commands, enable IPC in the config.

Example: Enable IPC & WS via config.json
"rpc": {
    // Enable RPC communication over 'ipc' and 'ws'
    "modes": ["ipc", "ws"]

    // 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"
},

Alternatively, start Klayr Core with the flag --api-ipc to enable IPC:

Example: Enable IPC via flag
klayr-core start --api-ipc
Please note that specifying any of the --api-ipc, --api-ws, or --api-http flags in the klayr-core start command overrides the rpc.modes settings in the config.json.

1. 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.