Skip to main content

MANTRA Chain

Installation

tip

You should update the MONIKER, WALLET, and PORT variables in the Setting up environment variables section. Make sure the port you specify is not already in use.

Check for ports already in use by visually inspecting the output of the lsof -i -P -n | grep LISTEN command. Almost all Cosmos chain nodes use ports xx317, xx656, xx657, and xx090. Therefore, avoid using ports starting with xx if they are already occupied.

Update OS

sudo apt update && sudo apt upgrade -y

Installation of required packages

sudo apt install curl git wget htop tmux build-essential jq make lz4 gcc unzip jq -y

Installation of go (if you need)

cd ~
VER="1.21.5" # Make sure that this version does not broke any other apps you run!
wget "https://golang.org/dl/go$VER.linux-amd64.tar.gz"
rm -rf /usr/local/go
tar -C /usr/local -xzf "go$VER.linux-amd64.tar.gz"
rm "go$VER.linux-amd64.tar.gz"
[ ! -f ~/.bash_profile ] && touch ~/.bash_profile
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bash_profile
source $HOME/.bash_profile
[ ! -d ~/go/bin ] && mkdir -p ~/go/bin

Setting up environment variables

echo "export WALLET="wallet"" >> $HOME/.bash_profile
echo "export MONIKER="NGSolutionsWASHERE"" >> $HOME/.bash_profile
echo "export MANTRA_CHAIN_ID="mantra-hongbai-1"" >> $HOME/.bash_profile
echo "export MANTRA_PORT="11"" >> $HOME/.bash_profile
source $HOME/.bash_profile

Downloading and installing node

info

If you have any other node that requires a different version of libwasmvm, you may break it! For instance, Hedgeblock requires libawasm v1.3.0. Please be careful!

cd $HOME
sudo wget -O /usr/lib/libwasmvm.x86_64.so https://github.com/CosmWasm/wasmvm/releases/download/v1.3.1/libwasmvm.x86_64.so
wget https://github.com/MANTRA-Finance/public/raw/main/mantrachain-hongbai/mantrachaind-linux-amd64.zip
unzip mantrachaind-linux-amd64.zip
rm mantrachaind-linux-amd64.zip
mv mantrachaind $HOME/go/bin

Initializing the node

mantrachaind init $MONIKER --chain-id $MANTRA_CHAIN_ID
sed -i -e "s|^node *=.*|node = \"tcp://localhost:${MANTRA_PORT}657\"|" $HOME/.mantrachain/config/client.toml

Downloading genesis and addressbook

cd $HOME
curl https://mantra.rpc.ngsolutions.xyz/genesis? | jq ".result.genesis" > .mantrachain/config/genesis.json
wget -O $HOME/.mantrachain/config/addrbook.json https://snapshots.ngsolutions.xyz/addrbook/mantrachain/addrbook.json

Setting seeds and peers

PEERS="8e96bd303a8b5aacc61f618872519cd0c75243d6@8e96bd303a8b5aacc61f618872519cd0c75243d6:23656,1a46b1db53d1ff3dbec56ec93269f6a0d15faeb4@1a46b1db53d1ff3dbec56ec93269f6a0d15faeb4:22656,0c64e1df3e948e4f75666697d424c9c8bff0379e@0c64e1df3e948e4f75666697d424c9c8bff0379e:26656,bed87bd17a31c2920536a5a8e77f77eec8e12f0e@bed87bd17a31c2920536a5a8e77f77eec8e12f0e:12656,2118a36f67e5c83ca7e4271830073eb3b63342f6@2118a36f67e5c83ca7e4271830073eb3b63342f6:56266,c6a28b964edbd6fe662bd07156cdb04b89886549@c6a28b964edbd6fe662bd07156cdb04b89886549:50056,e1b058e5cfa2b836ddaa496b10911da62dcf182e@e1b058e5cfa2b836ddaa496b10911da62dcf182e:36656,e6921a8a228e12ebab0ab70d9bcdb5364c5dece5@e6921a8a228e12ebab0ab70d9bcdb5364c5dece5:47656,33cf22311a510b01552fb1e323add74c641f01c5@33cf22311a510b01552fb1e323add74c641f01c5:18656,19cbfb1c73a0c0f3534a8a0d65150b9e2caad07a@19cbfb1c73a0c0f3534a8a0d65150b9e2caad07a:16656"
sed -i -e "s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.mantrachain/config/config.toml

Setting custom ports

Updating ports in app.toml

sed -i.bak -e "s%:1317%:${MANTRA_PORT}317%g;
s%:8080%:${MANTRA_PORT}080%g;
s%:9090%:${MANTRA_PORT}090%g;
s%:9091%:${MANTRA_PORT}091%g;
s%:8545%:${MANTRA_PORT}545%g;
s%:8546%:${MANTRA_PORT}546%g;
s%:6065%:${MANTRA_PORT}065%g" $HOME/.mantrachain/config/app.toml

Updating ports in config.toml

sed -i.bak -e "s%:26658%:${MANTRA_PORT}658%g;
s%:26657%:${MANTRA_PORT}657%g;
s%:6060%:${MANTRA_PORT}060%g;
s%:26656%:${MANTRA_PORT}656%g;
s%^external_address = \"\"%external_address = \"$(wget -qO- eth0.me):${MANTRA_PORT}656\"%;
s%:26660%:${MANTRA_PORT}660%g" $HOME/.mantrachain/config/config.toml

Configuring pruning settings

sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.mantrachain/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.mantrachain/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.mantrachain/config/app.toml

Setting gas and other configurations

sed -i 's|minimum-gas-prices =.*|minimum-gas-prices = "0.0002uom"|g' $HOME/.mantrachain/config/app.toml
sed -i -e "s/prometheus = false/prometheus = true/" $HOME/.mantrachain/config/config.toml
sed -i 's/max_num_inbound_peers =.*/max_num_inbound_peers = 50/g' $HOME/.mantrachain/config/config.toml
sed -i 's/max_num_outbound_peers =.*/max_num_outbound_peers = 50/g' $HOME/.mantrachain/config/config.toml
sed -i -e "s/^indexer *=.*/indexer = \"null\"/" $HOME/.mantrachain/config/config.toml

Creating service file

sudo tee /etc/systemd/system/mantrachaind.service > /dev/null <<EOF
[Unit]
Description=Mantra Node
After=network-online.target
[Service]
User=$USER
WorkingDirectory=$HOME/.mantrachain
ExecStart=$(which mantrachaind) start --home $HOME/.mantrachain
Restart=on-failure
RestartSec=5
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF

Snapshot

danger

Important: Back Up Your Validator Key

Before resetting your node, ensure you have a backup of your priv_validator_key.json file. This is especially important if you've already created a validator. Without a backup, resetting the node will result in lost access and require you to create a new validator from scratch.

info

This script creates a copy of your priv_validator_state.json and priv_validator_key.json files. It then copies the original private files back after downloading the snapshot. However, use this script with caution to avoid any potential failures.

  1. Create Backups of Private Files.

    cp $HOME/.mantrachain/data/priv_validator_state.json $HOME/priv_validator_state.json.mantrachain.backup
    cp $HOME/.mantrachain/config/priv_validator_key.json $HOME/priv_validator_key.json.mantrachain.backup
  2. Reset Node and Download Snapshot

    mantrachaind tendermint unsafe-reset-all --home $HOME/.mantrachain --keep-addr-book
    curl https://snapshots.ngsolutions.xyz/snapshots/mantrachain/snap_mantrachain.tar.lz4 | lz4 -dc - | tar -xf - -C $HOME/.mantrachain
  3. Restore Backed Up Files

    cp $HOME/priv_validator_state.json.mantrachain.backup $HOME/.mantrachain/data/priv_validator_state.json
    cp $HOME/priv_validator_key.json.mantrachain.backup $HOME/.mantrachain/config/priv_validator_key.json

Enabling and starting the service

# You need to inspect logs visually after the  to make sure that it is working
sudo systemctl daemon-reload
sudo systemctl enable mantrachaind
sudo systemctl restart mantrachaind && journalctl -u mantrachaind -f --no-hostname -o cat

Creating a wallet

You need to create or import a wallet to request test tokens. If you dont have any tokens, you will not be able to create a validator.

# Following command creates a new wallet.
# Copy mnemonics to a safe place
# If you lost your mnemonics you will not be able to recover this wallet.
mantrachaind keys add $WALLET

# If you want to import a wallet using mnemonics, execute following command and enter your mnemonics
mantrachaind keys add $WALLET --recover

# Get your keys and their addresses to request faucet
mantrachaind keys list

Creating a validator

Before you begin:

It's crucial to ensure your node is synchronized with the network before attempting to create a validator. This ensures your validator operates with the latest blockchain data.

Checking Synchronization Status:

Use the following snippet to check your node's synchronization status. If the snippet returns false, your node is in sync and ready to proceed. However, if it returns true, your node is still catching up. In that case, please wait until the synchronization completes before creating a validator.

mantrachaind status | jq -r .sync_info.catching_up

Creating a Validator:

The following snippet will create a validator.json file in your node's home directory. This file stores the details necessary to create your validator. While you can edit the validator.json file later, keep in mind that doing so may incur token fees. Therefore, it's important to ensure the information within the file is accurate before proceeding.

cd $HOME
# Create validator.json file
echo "{
\"pubkey\":{\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"$(mantrachaind comet show-validator | grep -Po '\"key\":\s*\"\K[^"]*')\"},
\"amount\": \"1000000uom\",
\"moniker\": \"NGSolutionsWasHere\",
\"identity\": \"\",
\"website\": \"\",
\"security\": \"\",
\"details\": \"All heil NGSolutions\",
\"commission-rate\": \"0.1\",
\"commission-max-rate\": \"0.2\",
\"commission-max-change-rate\": \"0.01\",
\"min-self-delegation\": \"1\"
}" > .mantrachain/validator.json

Next Steps:

Once you're satisfied with the contents of validator.json, you can proceed with creating the validator using the information stored within the file.

# Create a validator using the JSON configuration
mantrachaind tx staking create-validator validator.json \
--from $WALLET \
--chain-id $MANTRA_CHAIN_ID \
--fees 500uom

Delegate to yourself

You might need to update number of tokens before executing the following command.

mantrachaind tx staking delegate \
$(mantrachaind keys show $WALLET --bech val -a) 2000000uom \
--from $WALLET \
--chain-id $MANTRA_CHAIN_ID \
--fees=500uom

Deleting the node completely (if you need)

danger

Make sure that you backed up any required files to setup later! Do not lost your validator or wallet!

sudo systemctl stop mantrachaind
sudo systemctl disable mantrachaind
rm -rf /etc/systemd/system/mantrachaind.service
rm $(which mantrachaind)
rm -rf $HOME/.mantrachain
sed -i "/MANTRA_/d" $HOME/.bash_profile