How to run Pactus in Command Line Mode?

Preface

Pactus can be run in different modes, including the command-line interface (CLI) and the graphical user interface (GUI). This tutorial will guide you through the steps to run Pactus in CLI mode, suitable for advanced users.

Prerequisites

Before proceeding with the steps below, ensure that you have the following:

  • A computer running Windows, macOS, or Linux
  • Suitable internet connection

Download

To get started, download and extract the Pactus CLI file from here. Once you have downloaded and extracted the Pactus CLI file, you can proceed to the next step.


Initializing the Node

Now you need to create a wallet and setup a working directory for your node. A working directory is a place where you save blockchain data and wallets. Open the Terminal and run the following command:

./pactus-daemon init

This command creates your wallet and setup the working working directory at ~/pactus.

pactus-daemon.exe init

This command creates your wallet and setup the working working directory at C:\Users\<USER_NAME>\pactus.

Working director

By default the working directory that store the blockchain data is set to ~/pactus in Unix-like systems. For Windows it is set to C:\Users\<USER_NAME>\pactus.

If you wish to select or specify a different path, use the --working-dir option.
Wallet seed is important

Keep your wallet seed phrase private and secure. If someone else gains access to your seed phrase, they can control your wallet and funds.

The working directory contains:

  • Default wallet
  • Genesis file
  • Config file

Feel free to explore the contents of these files as needed, particularly the config file. The config file contains parameters that can customize your node.

Restoring the Node

If you ever need to restore your node, for instance on a new device, you can use the --restore option followed by your mnemonic:

./pactus-daemon init --restore "<your-mnemonic>"

Replace <your-mnemonic> with your previously noted mnemonic phrase. This command will restore your wallet in the ~/pactus directory.

pactus-daemon.exe init --restore "<your-mnemonic>"

Replace <your-mnemonic> with your previously noted mnemonic phrase. This command will restore your wallet in the C:\Users\<USER_NAME>\pactus directory.


Running the Node

Now you can start the node and sync with the network. Run the following command in the Terminal:

./pactus-daemon start
pactus-daemon.exe start

When the Pactus node starts running, it begins syncing with the network. This process may take some time, as your node needs to download and verify the entire blockchain history. Please be patient while your node syncs.

Default Ports

The default network ports in Pactus are defined as follows. It is recommended not to change these default ports:

  • P2P port is set to 21888. P2P supports both UDP and TCP protocols.
  • gRPC port is set to 50051. The gRPC module is enabled by default for localhost.
  • gRPC-gateway is set to 8080. gRPC-gateway is disabled by default.
  • Nanomsg port is set to 40899. The Nanomsg service is disabled by default.

Running Pactus in the Background

To run Pactus commands in the background and keep them running even after you close your terminal or log out, you can use terminal multiplexer software. Terminal multiplexers allow you to create and manage multiple terminal sessions within a single window.

Two popular terminal multiplexer options are:

  1. tmux: Tmux is a terminal multiplexer that
  2. lets you create, manage, and detach terminal sessions.
  3. You can install tmux on Unix-like systems using your package manager (e.g., apt, brew, yum).

    Here’s how to use tmux to run Pactus in the background:

    • Start a new tmux session: tmux
    • Run your Pactus command within the tmux session.
    • Detach from the tmux session: Press Ctrl-b, followed by d.
    • Reattach to the tmux session later to check the progress: tmux attach-session
  4. screen: GNU Screen is another terminal multiplexer that
  5. allows you to run terminal sessions in the background.

    Here’s how to use screen to run Pactus in the background:

    • Start a new screen session: screen
    • Run your Pactus command within the screen session.
    • Detach from the screen session: Press Ctrl-a, followed by d.
    • Reattach to the screen session later to check the progress: screen -r

Choose the terminal multiplexer that suits your preference and install it using your system’s package manager. With these tools, you can run Pactus commands in the background with ease.


Become validator

To become a validator and participate in the consensus algorithm to earn rewards, you first need to stake some coins. In the next tutorial, we will explain how to send a Bond transaction to become a validator.


By running a Pactus node, you contribute to the decentralization and security of the Pactus blockchain network. Thank you for your participation!