Install Prerequisites

In this section, we will set up our machine and install the prerequisites for developing, deploying and interacting with smart contracts on MANTRA Chain.

Go

You can set up Go following the official documentation. The latest versions of mantrachaind require go version v1.18+.

Rust

Assuming you have never worked with Rust, you will first need to install some tooling.

The standard approach is to use rustup to maintain dependencies and handle updating multiple versions of cargo and rustc, which you will be using.

Installing Rust in Linux and Mac

First, install rustup. Once installed, make sure you have the wasm32 target:

rustup default stable
cargo version
# If this is lower than 1.55.0+, update
rustup update stable

rustup target list --installed
rustup target add wasm32-unknown-unknown

wasm32-unknown-unknown states the target specification, and is called "target triple" consisting of three strings separated by hyphens.

Strings represent architecture, vendor, and operating system respectively. unknown means there is no specifications for the target and the application is more flexible.

Read the rust docs for a more detailed explanation.

Installing Rust in Windows 10

First, download and execute rustup-init.exe from rustup.rs or rust-lang.org.

If requested, manually download and install Visual C++ Build Tools 2019, from https://visualstudio.microsoft.com/visual-cpp-build-tools/ . Make sure "Windows 10 SDK" and "English language pack" are selected.

Continue running rustup-init.exe, and proceed with the installation.

Optionally:

Install the wasm32 target:

rustup default stable
cargo version
# If this is lower than 1.55.0, update
rustup update stable

rustup target list --installed
rustup target add wasm32-unknown-unknown

Docker

Docker is essential for setting up and running applications in isolated environments. You can install Docker by following the instructions on the official Docker website for your respective operating system. If you are a Windows user, make sure to activate the WSL integration in Docker Desktop settings.


Install cargo-generate package

Cargo-generate is a command-line tool used in Rust programming for generating new Rust projects from predefined templates. It allows developers to quickly set up a new project with a specific structure, dependencies, and configuration.

cargo install cargo-generate --features vendored-openssl

cargo install cargo-run-script

mantrachaind

mantrachaind is the backbone of the CosmWasm platform for MANTRA DuKong Chain. The binary is pre-built for both Linux and MacOS clients.

You can find all the pre-built binaries on the MANTRA GitHub Repo.

On Linux:

# Download the CLI
curl -LO < https://github.com/MANTRA-Chain/mantrachain/releases/download/v1.0.0-rc3/mantrachaind-1.0.0-rc3-darwin-arm64>

# Unzip the CLI
unzip mantrachaind-1.0.0-rc3-darwin-arm64

On MacOS:

# Download the CLI for Intel chips
curl -LO <https://github.com/MANTRA-Chain/mantrachain/releases/download/v1.0.0-rc3/mantrachaind-1.0.0-rc3-darwin-amd64.tar.gz>

# Download the CLI for Silicon chips (M1, M2...)
curl -LO <https://github.com/MANTRA-Chain/mantrachain/releases/download/v1.0.0-rc3/mantrachaind-1.0.0-rc3-darwin-arm64.tar.gz>

# Extract the CLI
tar -xzvf mantrachaind-1.0.0-rc3-darwin-*.tar.gz

You should see the following output, or similar, after executing the mantrachaind command.

Usage:
mantrachaind [command]

Available Commands:
    add-genesis-account Add a genesis account to genesis.json
    collect-gentxs      Collect genesis txs and output a genesis.json file
    config              Create or query an application CLI configuration file
    debug               Tool for helping with debugging your application
    export              Export state to JSON
    gentx               Generate a genesis tx carrying a self delegation
    help                Help about any command
    init                Initialize private validator, p2p, genesis, and application configuration files
    keys                Manage your application's keys
    migrate             Migrate genesis to a specified target version
    query               Querying subcommands
    rollback            rollback cosmos-sdk and tendermint state by one height
    start               Run the full node
    status              Query remote node for status
    tendermint          Tendermint subcommands
    tx                  Transactions subcommands
    validate-genesis    validates the genesis file at the default location or at the location passed as an arg
    version             Print the application binary version information

Flags:
    -h, --help                help for mantrachaind
        --home string         directory for config and data (default "/Users/<your-user-name>/.mantrachain")
        --log_format string   The logging format (json|plain) (default "plain")
        --log_level string    The logging level (trace|debug|info|warn|error|fatal|panic) (default "info")
        --trace               print out full stack trace on errors

if you receive the following error: mantrachaind: error while loading shared libraries: libwasmvm.x86_64.so: cannot open shared object file: No such file or directory you will need to install the CosmWasm library libwasmvm.x86_64.so (see below).

Install CosmWasm library

More information can be found in here: https://github.com/CosmWasm/wasmvm

If you are on a x86_64 system:

sudo wget -P /usr/lib <https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0/libwasmvm.x86_64.so>

On arm64 (i.e. Apple silicon chips):

sudo wget -P /usr/lib <https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0/libwasmvm.aarch64.so>

On MacOS, you might not be allowed to write on /usr/lib even as root.
If that’s the case, try storing libwasmvm.*.so on /usr/local/lib instead.
For certain operating systems, you might encounter architecture compatibility issues with mantrachaind, as the binary is designed for the AMD64 (x86_64) architecture. This can make direct execution on some systems difficult.

To address this, you have a few options: use Docker to emulate an x86_64 environment on your ARM64 Mac, utilize GitHub Codespaces, or run a virtual machine that supports the x86_64 architecture.
   
Additionally, you can refer to the section on "Deployment Using TypeScript (Windows/Linux/Mac)" to set up your dev environment and deploy your contracts on the DuKong Testnet.

Setting up jq

jq is a lightweight and flexible command-line JSON processor. It helps us to slice and filter and map and transform structured JSON data.

Installation will vary depending on your operating system (i.e. Linux, MacOS or Windows).

Linux (Ubuntu / Debian):

sudo apt-get install jq

MacOS:

brew install jq

Windows:

winget install jqlang.jq

Alternatively, see the 'Download jq' site for other options.

Git

Git is a free and open-source version control system that allows you to track changes made to code, collaborate with others, and maintain different versions of your project. It's primarily used for source code management, but it can be used to track changes in any set of files.

Linux (Ubuntu / Debian):

sudo apt-get install git

MacOS:

brew install git

Windows:

Go to the official Git download page and download the latest version of Git for Windows.


Setting up your IDE

We will need a good IDE for developing smart contracts with Rust. The following development environments are highly recommended and coupling them with the corresponding Rust plugins will help you learn the syntax, especially if you have no prior experience.

  • VSCode offers great support for Rust, especially when coupled with the rust-analyzer extension. This extension makes use of the rust compiler to type-check all your code as you save. This gives the same error messages as the actual compiler would and highlights the errors, but it can be a bit slow to respond (as it runs the compiler). It is a solid option, particularly if you are used to VSCode.

  • Another option is RustRover, Jetbrains’ IDE specifically designed for Rust development. It offers a robust suite of features to streamline the development process, including intelligent code completion, real-time error detection, and powerful refactoring tools. RustRover enhances productivity with its customizable interface, seamless integration with version control systems, and comprehensive debugging capabilities. It is highly recommended, more so, if you are coming from another Jetbrain product (eg. Goland).

There are other editors out there with varying degrees of Rust support. However, unless you have a strong preference for another editor (e.g., Sublime, Emacs, Vim) , trying one of the two above is recommended, especially if you are new to Rust. Once you are confident in the language, you can always use another editor and customize it to your liking.

Last updated