Marsd
This guide will explain how to install the marsd binary (Mars CLI) onto your system as a command-line interface tool for interacting with nodes on Mars Hub.
While marsd
is a requirement to run a full node, you don't have to run a full local node yourself to interact with the network. You can specify a remote node with the —node
flag.
With marsd
connected to a remote node you can:
- Generates keys
- Send transactions
- Deploy and interact with contracts
- and more
Requirements
To install Marsd, you will need the following:
- Linux or macOS operating system
- Go v1.19+
Setup
Login to your user account (you don't want to use root) and install some essential packages:
_4sudo apt update_4sudo apt upgrade_4sudo apt install build-essential git vim jq libleveldb-dev_4sudo apt autoremove
Install the Go programming language:
_4curl -LO https://golang.org/dl/go1.18.3.linux-amd64.tar.gz_4tar xfz ./go1.18.3.linux-amd64.tar.gz_4sudo mv go /usr/local_4go version
Configure Environment Variables
After installing Go, it is recommended to configure related environment variables:
_5# ~/.bashrc_5export GOROOT=/usr/local/go_5export GOPATH=$HOME/.go_5export GOBIN=$GOPATH/bin_5export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
The provided code block is a set of environment variable assignments in a bash configuration file (~/.bashrc). These environment variables are commonly used in Go programming and their purpose is to specify the location of Go installation, workspace, and executable files:
export GOROOT=/usr/local/go
assigns the location of the Go installation directory to the GOROOT environment variable. The export keyword ensures that this variable is accessible to child processes. If using a package manager such as homebrew, this location may vary.export GOPATH=$HOME/.go
assigns the location of the Go workspace directory to the GOPATH environment variable. The workspace is where Go source code and its dependencies are stored. By default, the workspace is located in $HOME/go but can be customized using this environment variable.export GOBIN=$GOPATH/bin
assigns the location of the Go executable files to the GOBIN environment variable. This variable specifies the directory where Go binary files will be installed when using go install command.- Finally,
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
adds the directories specified in GOPATH/bin and GOROOT/bin to the system's PATH variable. This makes it possible to execute Go binaries from any directory in the terminal by simply typing their name.
Overall, this is a convenient way to set up the Go development environment by specifying the important directories and their locations as environment variables.
Installing Marsd
To install Marsd, clone the Mars Hub repository, checkout the latest tag (e.g. v1.0.0), and compile the code:
_4git clone https://github.com/mars-protocol/hub.git _4cd hub_4git checkout <tag>_4make install
A marsd
executable will be created in the $GOBIN directory.
Generate Operator Key
Each node comes with three private keys: an operator key, a consensus key, and a node key. If you are connecting to a remote node, you only need an operator key to transact. Later sections will cover consensus and node keys as well.
To generate your operator key, run the following command:
_1marsd keys add <key-name>
Make sure you save the mnemonics! After you end your terminal session, your keys cannot be recovered.
To use an existing seed phrase, run the following command:
_1marsd keys add <key-name> --recover
Connect to a Remote Node
At this point, you can begin interacting with the Mars blockchain by connecting to a remote note.
Martians who prefer to not operate a node can connect to a remote node with Marsd by appending the --node
flag at the end of requests along with an RPC endpoint in the https://<host>:<port>
format. Alternatively, Martians can configure a default node using the following command:
_1marsd config node https://<host>:<port>
If you are connecting to a remote node, select a node operator that you can trust. Malicious operators can alter query results and censor transactions. Mars contributors currently maintain the following RPC endpoints for public use:
Mainnet (mars-1
): https://rpc.marsprotocol.io:443
Testnet (ares-1
): https://testnet-rpc.marsprotocol.io:443
A list of public RPC endpoints can also be found in the Cosmos chain registry.
To learn about the list of available commands, run marsd --help
in your terminal. For more information about a specific command, append the --help
flag at the end of your request, for example:
_2marsd query --help_2marsd query bank --help
Commands
This section describes essential commands for validators from marsd, the command line interface that connects a running marsd process.
keys
Manages Keyring commands. For a list of syntax and subcommands, see the keys subcommands.
query
Manages queries. For a list of syntax and subcommands, see the query subcommands.
start
Runs the full node application with Tendermint in or out of process. By default, the application runs with Tendermint in process:
_1marsd start
status
Displays the status of a remote node:
_1marsd status
tx
Retrieves a transaction by its hash, account sequence, or signature. For a list of full syntax and subcommands, see the tx subcommands.
Syntax to query by hash:
_1marsd query tx <hash>
Syntax to query by account sequence:
_1marsd query tx --type=acc_seq <address>:<sequence>
Syntax to query by signature:
_1marsd query tx --type=signature <sig1_base64,sig2_base64...>
txs
Retrieves transactions that match the specified events where results are paginated:
_1marsd query txs --events '<event>' --page <page-number> --limit <number-of-results>
Example:
_1marsd query txs --events 'message.sender=cosmos1...&message.action=withdraw_delegator_reward' --page 1 --limit 30