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 directory at ~/pactus
.
pactus-daemon.exe init
This command creates your wallet and setup the working directory at C:\Users\<USER_NAME>\pactus
.
By default the working directory that store the blockchain data stores in
~/pactus
in Unix-like systems.
For Windows it stores in C:\Users\<USER_NAME>\pactus
.If you wish to select or specify a different path, use the
--working-dir
option.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.
Importing data (Optional)
To speed up the syncing process, you can import a snapshot of the blockchain from a centralized server. This will start your node in Pruned Mode:
./pactus-daemon import
pactus-daemon.exe import
Starting with version 1.4.0, Pactus supports Pruned Mode. In this mode, you don’t need to download the entire blockchain; instead, you can download recent blocks from the last 10 days. This significantly speeds up the syncing process.
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 not recommended to change these default ports:
- P2P port is
21888
. P2P supports both UDP and TCP protocols. - gRPC port is
50051
. The gRPC module is enabled by default for localhost. - gRPC-gateway port is
8080
. The gRPC-gateway is disabled by default. - JSON-RPC port is
8545
. The JSON-RPC service is disabled by default. - Nanomsg port is
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:
tmux: Tmux is a terminal multiplexer that
lets you create, manage, and detach terminal sessions.
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 byd
. - Reattach to the tmux session later to check the progress:
tmux attach-session
- Start a new tmux session:
screen: GNU Screen is another terminal multiplexer that
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 byd
. - Reattach to the screen session later to check the progress:
screen -r
- Start a new screen session:
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.