Smart Contracts Installation
In this section, we will gear up your workspace for developing, deploying and enjoying smart contracts on Cosmos SDK.
For developing complex smart contracts, you will likely want to run a full node on a testnet. See the validators section under Joining Testnets for more information.

Go

You can setup golang by following the official documentation. The latest versions of junod require go version v1.16.

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:
1
rustup default stable
2
cargo version
3
# If this is lower than 1.49.0+, update
4
rustup update stable
5
6
rustup target list --installed
7
rustup target add wasm32-unknown-unknown
Copied!

Installing Rust in Windows 10

If working on a validator or a server, you should use Linux if possible. You will have a much better time...
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 here. Make sure "Windows 10 SDK" and "English language pack" are selected.
Continue running rustup-init.exe, and proceed with the installation.
Optionally:
  • Download and install gvim, and modify the Env vars to add <gvim folder> to the PATH.
  • Download and install git for windows. Modify the Env vars to add <git folder>\bin to PATH.
  • Turn on Developer Mode (Settings -> Update and Security: For Developers) and enable Device Discovery, to be able to access the Windows 10 server through ssh.
Install the wasm32 target:Copy
1
rustup default stable
2
cargo version
3
# If this is lower than 1.49.0, update
4
rustup update stable
5
6
rustup target list --installed
7
rustup target add wasm32-unknown-unknown
Copied!
For those new to rust, the stable channel comes out every 6 weeks with a stable release.

Building Juno for testnet use

A testnet running the Juno chain has been launched to save you of the hassle of running a local network and speed up your development.
Use go 1.17.x for compiling the junodexecutable if you are building from source. If you already are running a validator node, it's likely junod is already accessible. If which junod shows output, then you're probably good to go.
1
# clone juno repo
2
git clone https://github.com/CosmosContracts/juno.git && cd juno
3
4
# get current testnet tag
5
git fetch --tags
6
git checkout v2.0.0-alpha.3
7
8
# build juno executable
9
make install
10
11
which juno
Copied!
If you have any problems here, check your PATH. make install will copy junod 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.

Getting started with writing contracts

There are two tutorials provided here in the docs, which will give you an overview of working with smart contracts and their basic functions. However if you are an experienced programmer wanting to immediately start writing CosmWasm contracts, then we recommend working through their excellent tutorial.

Running locally

Running locally is harder. Like on the testnet, you will need to make sure that your chosen tag for the junod binary and version of CosmWasm line up.
As of 2021-10-05, the correct tag to use is the same as the testnet tag above.
You will then need to set up your local chain to develop against. You can do this with Starport, if you're comfortable with that, or alternatively use the following script adapted from the CosmWasm team.
Note that on line 10 the CHAIN_ID is hardcoded. Currently this is lucina, but it will change in future to moneta.
1
#!/bin/bash
2
3
set -e
4
5
# lightly adapted from the cool cats at Confio / cosmwasm
6
# as always, thanks and mega props
7
8
APP_HOME="~/.juno"
9
RPC="http://localhost:26657"
10
CHAIN_ID="uni"
11
# initialize junod configuration files
12
junod init testmoniker --chain-id ${CHAIN_ID} --home ${APP_HOME}
13
14
# add minimum gas prices config to app configuration file
15
sed -i -r 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025ujunox"/' ${APP_HOME}/config/app.toml
16
17
# Create main address
18
# --keyring-backend test is for testing purposes
19
# Change it to --keyring-backend file for secure usage.
20
export KEYRING="--keyring-backend test --keyring-dir $HOME/.juno_keys"
21
junod keys add main $KEYRING
22
23
# create validator address
24
junod keys add validator $KEYRING
25
26
# add your wallet addresses to genesis
27
junod add-genesis-account $(junod keys show -a main $KEYRING) 10000000000ujunox --home ${APP_HOME}
28
junod add-genesis-account $(junod keys show -a validator $KEYRING) 10000000000ujunox --home ${APP_HOME}
29
30
# add second address as validator's address
31
# validator is the key name
32
junod gentx validator 1000000000ujunox --home ${APP_HOME} --chain-id ${CHAIN_ID} $KEYRING
33
34
# collect gentxs & add to genesis
35
junod collect-gentxs --home ${APP_HOME}
36
37
# validate the genesis file
38
junod validate-genesis --home ${APP_HOME}
39
40
# run the node
41
junod start --home ${APP_HOME}
Copied!
Last modified 12d ago