Deploying a Smart Contract in CUDOS — Update February 2022

Prerequisites

1) RPC Node

2) Rust

# Install rustup.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Use the latest stable version.
$ rustup default stable
# Add the wasm32 target and make sure it was installed correctly.
$ rustup target add wasm32-unknown-unknown
$ rustup target list --installed

Smart Contract

Download an Existing Smart Contract

$ git clone --depth 1 --branch v0.9.0 https://github.com/CosmWasm/cw-plus.git

Compilation

# Go to root directory of CW20 contract.
$ cd cw-plus
# Optimize and compile the smart contract.
$ docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/workspace-optimizer:0.12.5
# Make sure the "binary-builder" is in the list of running containers.
$ docker ps
# Copy the .wasm executable into the /usr/cudos directory of the binary-builder.
$ docker cp artifacts/cw20_base.wasm binary-builder:/usr/cudos
# Install jQuery.
$ docker exec -it binary-builder apt update -y
$ docker exec -it binary-builder apt install jq -y

Deployment

# Create a new owner account (if needed).
$ docker exec -it binary-builder cudos-noded keys add owner \
--keyring-backend file
# To recover an account, add the --recover flag to the command above.
# Check balance to see if the tokens from the faucet have arrived.
$ docker exec -it binary-builder cudos-noded q bank balances <OWNER_ADDR> --node https://sentry1.gcp-uscentral1.cudos.org:26657
  • <OWNER_ADDR> is the owner account’s cudos1... address.
$ docker exec -it binary-builder cudos-noded tx wasm store /usr/cudos/cw20_base.wasm \
--from owner \
--keyring-backend file \
--chain-id cudos-testnet-public-2 \
--node https://sentry1.gcp-uscentral1.cudos.org:26657 \
--gas auto \
--gas-adjustment 1.3 \
-y | tee /dev/tty | tail -1 | tr -d '\r' | jq -r '.logs[0].events[-1].attributes[-1].value' | tee /dev/tty

Instantiation

$ INIT=$(jq -n --arg address <OWNER_ADDR> '{"name":"<TOKEN_NAME>","symbol":"<TOKEN_SYMBOL>","decimals":<DECIMALS>,"initial_balances":[<ACCOUNTS>],"mint":{"minter":$address,"cap":"<TOKEN_CAP>"}}' | tee /dev/tty)
  • <OWNER_ADDR> is the owner account’s
  • <TOKEN_NAME> is the name you’d like to give your CW20 token, e.g. “Super Cudos”
  • <TOKEN_SYMBOL> is the denominator of your CW20 token, e.g. “scudos”
  • <DECIMALS> is the number of decimal places your token should have, e.g. 3 (=smallest value would be 0.001)
  • <ACCOUNTS> is an array of one or more JSON objects like {"address": "<CUDOS_ADDR>","amount":<TOKEN_AMOUNT>} , where <CUDOS_ADDR> is the cudos1... address that is given <TOKEN_AMOUNT> tokens on contract instantiation, e.g. {"address": "cudos1d0new9u2f80rcmmlw0zftxeh0385c2gwpmdv8v","amount":1000}
  • <TOKEN_CAP> is the maximum amount of tokens the minter can mint, e.g. “1000000000000”
$ docker exec -it binary-builder cudos-noded tx wasm instantiate <CONTRACT_ID> $INIT --from owner --label "CW20" --keyring-backend file --chain-id cudos-testnet-public-2 --node https://sentry1.gcp-uscentral1.cudos.org:26657 --gas auto --gas-adjustment 1.3 -y
  • <CONTRACT_ID> is the contract’s ID we got from deploying it
$ docker exec -it binary-builder cudos-noded q wasm list-contract-by-code <CONTRACT_ID> --node https://sentry1.gcp-uscentral1.cudos.org:26657 --output json | jq -s

Interacting with the Contract

$ CONTRACT_ADDR=$(docker exec -it binary-builder cudos-noded q wasm list-contract-by-code <CONTRACT_ID> --node https://sentry1.gcp-uscentral1.cudos.org:26657 --output json | jq -r '.contracts[-1]' | tee /dev/tty | tail -1 | tr -d '\r')
$ cd /path/to/cw-plus/contracts/<CONTRACT>
$ cargo schema
  • In our case, <CONTRACT> is cw20-base
$ TRANSFER=$(jq -n --arg address <RECIPIENT_ADDR> '{"transfer":{"amount":"1000000","recipient":$address}}')
  • <RECIPIENT_ADDR> is the cudos1... address of any account you want to send tokens to
$ docker exec -it binary-builder cudos-noded tx wasm execute $CONTRACT_ADDR $TRANSFER --from owner --keyring-backend file --chain-id cudos-testnet-public-2 --node https://sentry1.gcp-uscentral1.cudos.org:26657 --gas auto --gas-adjustment 1.3 -y
$ BALANCE=$(jq -n --arg address <RECIPIENT_ADDR> '{"balance":{"address":$address}}')
$ docker exec -it binary-builder cudos-noded q wasm contract-state smart $CONTRACT_ADDR $BALANCE --node https://sentry1.gcp-uscentral1.cudos.org:26657

--

--

--

Validator operator in 20+ PoS blockchains. Visit us at www.blockscape.network.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Finding the Articulation point

The Local Network Repository

What is the best word to start a game of Wordle

Collecting logs for Docker Rails application with Datadog

Logic and Sets — ADI #7

Git with Multiple Accounts

Getting started with Golang

Element.Black Forms Partnership With Entertainment Producer Gohzu Haruna

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
blockscapeLab

blockscapeLab

Validator operator in 20+ PoS blockchains. Visit us at www.blockscape.network.

More from Medium

Nothing Mean about Mean DAO

An Insight Into the Promising Future of FIL & SFIL

Zero Relayer Fee on Picasso

INTEGRATING DEXA COIN’S ($DEXA) RSS FEED WITH CRYPTO.COM