> ## Documentation Index
> Fetch the complete documentation index at: https://mantrachain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> In this section, the application we are running is called mantrachaind. We will walk through how to set up and configure the app - along with integrating the application as a system service.

# Running a node

Recommended Readings

* [Anatomy of a Cosmos SDK Application](https://docs.cosmos.network/main/learn/beginner/app-anatomy)
* [Setting up a keyring](https://docs.cosmos.network/main/user/run-node/keyring)

## Download latest release [#download-latest-release](#download-latest-release)

Latest chain release binaries can be found on [GitHub Releases](https://github.com/MANTRA-Chain/mantrachain/releases).

> [!NOTE]
>
> **Current Versions:**
>
> * **Mainnet (mantra-1)**: See [Chain Parameters](https://mantrachain.mintlify.site/resources/chain-parameters.md) for the latest mainnet version
> * **Testnet (mantra-dukong-1)**: Running latest release candidate for testing upcoming upgrades

You can download the `mantrachaind` executable and place it in a standard binary folder, such as `/usr/local/bin/` or similar. Remember to make it executable by running `sudo chmod +x mantrachaind`.

### Binary Check

Each `mantrachaind` binary is deployed with a corresponding .sha256 file that you can download, to verify the integrity of the build. Download the `sha256sum.txt` and verify the hash.

**Build From Source**

If you would like to build from source instead of using the release binary, you can compile and install the binary.

[go](https://go.dev/dl/) will be needed for this install

```bash theme={null}
make install
```

## Initialize the Chain

Before actually running the node, we need to initialize the chain, and most importantly its genesis file. This is done with the `init` subcommand:

> [!TIP]
>
> #### Public Testnet/Mainnet Chains
>
> We will have regularly updating public testnet chains along with our mainnet chain: `mantra-1`. Available networks to integrate with along with their requisite genesis files can be found [here](https://github.com/MANTRA-Chain/mantrachain/tree/main/networks).

```
mantrachaind init <moniker> --chain-id <chain-id>
```

Arguments:

* `moniker`: the custom username of your node, it should be human-readable.
* `chain-id`: The id of an existing chain that you want to join. Examples:
  * Testnet: `mantra-dukong-1`
  * Mainnet: `mantra-1`

\
The command above creates all the configuration files needed for your node to run, as well as a default genesis file, which defines the initial state of the network. Reminder to overwrite the default genesis if you're planning to exist to an existing chain!!

> [!TIP]
>
> **TIP**
>
> All these configuration files are in `~/.mantrachain` by default, but you can overwrite the location of this folder by passing the `--home` flag to each commands, or set an `$APPD_HOME` environment variable (where `APPD` is the name of the binary).

The `~/.mantrachain` folder has the following structure:

* `config.toml`: used to configure the CometBFT, learn more on [CometBFT's documentation](https://docs.cometbft.com/v0.37/core/configuration),
* `app.toml`: generated by the Cosmos SDK, and used to configure your app, such as state pruning strategies, telemetry, gRPC and REST servers configuration, state sync...

Both files are heavily commented, please refer to them directly to tweak your node.

```
.                                   # ~/.mantrachain
  |- data                           # Contains the databases used by the node.
  |- config/
      |- app.toml                   # Application-related configuration file.
      |- config.toml                # CometBFT-related configuration file.
      |- genesis.json               # The genesis file.
      |- node_key.json              # Private key to use for node authentication in the p2p protocol.
      |- priv_validator_key.json    # Private key to use as a validator in the consensus protocol.
```

## Connect to existing chains

#### I) Download the `genesis.json`

In order to connect to an existing public chain, we need to reuse an existing `genesis.json`

1. Go to [MANTRA-Chain/net](https://github.com/MANTRA-Chain/net) repository
2. Download the `genesis.json` of the chain you want to connect to, and put it into `~/.mantrachain/config`

#### II) Update configuration file

1. Install prerequisites tools before proceeding, ensure that `wget` is installed on your system, as it is required for running a Node. Having `wget` installed ensures seamless execution of the below script, allowing it to fetch necessary external resources without interruption.
2. Create a bash script with the following content:

```bash theme={null}
#!/usr/bin/env bash

CONFIG_TOML="$HOME/.mantrachain/config/config.toml"
APP_TOML="$HOME/.mantrachain/config/app.toml"
PERSISTENT_PEERS="" # Can be empty. Fill this one if you need to connect to particular peers
SEEDS=""

# configure minimum gas prices
sed -i.bak -e "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"40000000000amantra\"/g" $APP_TOML

# enable the api server
sed -i.bak '/\[api\]/,+3 s/enable = false/enable = true/' $APP_TOML

# configure optimised peering configuration
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$PERSISTENT_PEERS\"/" $CONFIG_TOML
sed -i.bak -e "s/^seeds =.*/seeds = \"$SEEDS\"/" $CONFIG_TOML
external_address=$(wget -qO- eth0.me)
sed -i.bak -e "s/^external_address *=.*/external_address = \"$external_address:26656\"/" $CONFIG_TOML
sed -i.bak -e "s/^filter_peers *=.*/filter_peers = \"true\"/" $CONFIG_TOML

# expose monitoring metrics via prometheus
sed -i.bak -e "s/^prometheus *=.*/prometheus = true/" $CONFIG_TOML
```

3. Update the `SEEDS` environment variable

Testnet (mantra-dukong-1):

* `SEEDS="7e061edecef73a700b699c785f61a44ca981ff7f@34.150.103.79:26656"`

Mainnet (mantra-1):

* `SEEDS="32276da966637722914411e16ca91bd37dcd1c28@35.220.157.87:26656,9f5235b418c87af4302619705d0bf4748249ca6b@34.18.33.96:26656"`
* Note: more seeds can be found at (Github)\[[https://github.com/cosmos/chain-registry/blob/master/mantrachain/chain.json](https://github.com/cosmos/chain-registry/blob/master/mantrachain/chain.json)]

> [!TIP]
>
> The seeds format is `node-id@ip:port,node-id@ip:port,...`

4. Run the script: `bash <script-name>.sh`

## Optional: start from an existing snapshot [#client-interaction](#client-interaction)

> [!TIP]
>
> When the node starts, it needs to sync all the data from other nodes, which could be time-consuming.
>
> In order to quicken the process, we are providing some existing data snapshots at [here](https://mantrachain.mintlify.site/operators/node-setup-and-deployment/validator-nodes/download-nodes-snapshots.md)

> [!TIP]
>
> **Warning**: If you are starting the node, please follow the procedure here in order to stop the current service and backup the important data: [https://www.polkachu.com/tendermint\_snapshots/mantra](https://www.polkachu.com/tendermint_snapshots/mantra)

1. Download the snapshot from: \
   [here](https://mantrachain.mintlify.site/operators/node-setup-and-deployment/validator-nodes/download-nodes-snapshots.md)
2. Install lz4
   1. Macos (homebrew) : `brew install lz4`
   2. Linux: [more info here](https://www.tecmint.com/install-lz4-linux/)
3. Decompress the snapshot

```bash theme={null}
lz4 -c -d <snapshot-name>.tar.lz4 | tar -x -C $HOME/.mantrachain
```

5. Update the file `~/.mantrachain/config/config.toml`
   1. Replace the value of `db_backend` by `pebbledb`, so it will looks like`db_backend = "pebbledb"`

## Testing the setup [#client-interaction](#client-interaction)

```bash theme={null}
mantrachaind start
```

> [!TIP]
>
> This command will start the node, which will sync its local data from the existing nodes

Wait for a few couple of seconds, and if you see the height growing: **success!** 🎉

## Client Interaction[​](https://docs.cosmos.network/main/user/run-node/run-node#client-interaction) [#client-interaction](#client-interaction)

When instantiating a node, GRPC and REST are defaulted to localhost to avoid unknown exposure of your node to the public. It is recommended to not expose these endpoints without a proxy that can handle load balancing or authentication is setup between your node and the public.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.