Skip to main content
Version: 1.0

Installation

In this section, we will set up your machine for developing, deploying and, hopefully, enjoying smart contracts on Cosmos SDK chains.

Go

You can set up golang following the official documentation. The latest versions of wasmd require go version v1.17+.

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.53.0+, update
rustup update stable

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

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.53.0, update
rustup update stable

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

For those new to rust, the stable channel comes out every 6 weeks with a stable release. The nightly channel is the bleeding edge and not only is it a version or two ahead (for testing), but it allows some extra unstable features, whose APIs may change. For compiling wasm, you will want to use stable. We use nightly to compile the runtime for wasmd, which needs it for the singlepass compiler with gas metering and more.

wasmd

wasmd is the backbone of CosmWasm platform. It is the implementation of a Cosmos zone with wasm smart contracts enabled.

This code was forked from the cosmos/gaia repository as a basis and then added x/wasm and cleaned up many gaia-specific files. However, the wasmd binary should function just like gaiad except for the addition of the x/wasm module.

git clone https://github.com/CosmWasm/wasmd.git
cd wasmd
git checkout v0.21.1
make install

# verify the installation
wasmd version
info

If you have any problems here, check your PATH. make install will copy wasmd to $HOME/go/bin by default, please make sure that is set up in your PATH as well, which should be the case in general for building Go code from source.

Further Information on the Cosmos SDK

These represent an instance of a blockchain that utilizes all of the stable features of the Cosmos SDK. As such, wasmd have all the same features (plus WASM smart contracts obviously). If you'd like to learn more about accessing those features take a look at the Gaia docs. If you'd like to learn more about getting started with the Cosmos SDK in general, take a look at the series of Tutorials that show how to build custom modules for application-specific blockchains.

Setting up your IDE

We will need a good editor to guide us through the experience. We highly recommend plugins that help you learn syntax, especially when just starting rust. There are two free editor environments we recommend, choose the one that is more familiar to you.

If you use VSCode (Download link) you just need to add the rust plugin. This is the best supported environment for RLS (Rust Language Server) and uses the rust compiler to type-check all your code on save. This gives the same error messages as the actual compiler would and highlights along the line of the code, 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.

RLS for VSCode

The other option is Intellij IDEA Community Edition (Download link), along with the Rust Plugin. This has fast support for inline language features. In particular, it shows the inferred types of variables, which can be very helpful, especially when working with (nested) generics. It catches most syntax errors very quickly, but not all of them. This means sometimes you have to look at compile failures to find the errors. If you are coming from another Intellij product (eg. Goland), use this:

RUST for Intellij

There are many more editors out there and some have varying degrees of rust support, at least syntax highlighting, but unless you have a strong preference to 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.