Counter

Deploy a simple counter contract that can increment and reset

Requires running a localnet.

Prerequisites

Install Rust and Cargo (via rustup).

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install some Rust and Cargo dependencies

rustup target add wasm32-unknown-unknown

cargo install cargo-generate --features vendored-openssl
cargo install cargo-run-script

Clone the repo

cargo generate --git https://github.com/CosmWasm/cw-template.git --name tutorial

cd tutorial/

Compile the contracts

To produce a simple, unoptimized build, run the following:

cargo wasm

It should produce a compiled *.wasm file in the artifacts/ directory.

Upload the contract

Instantiate a contract instance

Example output

Save the contract address for the next step.

Execute the contract

To increment the counter in the contract, run the following:

Example output

Query the contract

To query the counter, run the following:

Example output

Reset the counter

Query the counter (again)

Example output

Last updated

Was this helpful?