-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
"how-to-doc": "How to doc", | ||
"tags": { | ||
"display": "hidden" | ||
} | ||
}, | ||
"tutorial": "Tutorial" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Tutorial | ||
|
||
This module is a collection of guides for creating CosmWasm smart contracts. It will lead you step | ||
by step, and explain relevant topics from the easiest to the trickier ones. | ||
|
||
The point of these tutorials is not only to tell you about smart contracts API but also to show you | ||
how to write contracts in a clean and maintainable way. We will show you patterns that CosmWasm | ||
creators established and encouraged you to use. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setup-environment": "Environment setup", | ||
"cw-contract": "CosmWasm Contract" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CosmWasm contract writting tutorial | ||
|
||
This section is a step-by-step guide on how to write a CosmWasm contract. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
tags: ["tutorial"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
|
||
# Environment setup | ||
|
||
## Rust installation | ||
|
||
To work with CosmWasm smart contract, you will need Rust installed on your machine. If you don't | ||
have it, you can find installation instructions on | ||
[the Rust website](https://www.rust-lang.org/tools/install). | ||
|
||
I assume you are working with the stable Rust channel in this book. | ||
|
||
Additionally, you will need the Wasm rust compiler backend installed to build Wasm binaries. To | ||
install it, run: | ||
|
||
```shell copy filename="TERMINAL" | ||
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
## The cosmwasm-check utility | ||
|
||
An additional helpful tool for building smart contracts is the | ||
[`cosmwasm-check`](https://github.com/CosmWasm/cosmwasm/tree/main/packages/check) utility. It allows | ||
you to check if the wasm binary is a proper smart contract ready to upload into the blockchain. You | ||
can install it using cargo: | ||
|
||
```shell copy filename="TERMINAL" | ||
cargo install cosmwasm-check | ||
``` | ||
|
||
If the installation succeeds, you should be able to execute the utility from your command line. | ||
|
||
```shell copy filename="TERMINAL" | ||
cosmwasm-check --version | ||
``` | ||
|
||
The output should look like this: | ||
|
||
```shell | ||
Contract checking 1.2.3 | ||
``` | ||
|
||
## Verifying the installation | ||
|
||
To guarantee you are ready to build your smart contracts, you need to make sure you can build | ||
examples. Check out the [`cw-plus`](https://github.com/CosmWasm/cw-plus) repository and run the | ||
testing command in its folder: | ||
|
||
```shell copy filename="TERMINAL" | ||
git clone git@github.com:CosmWasm/cw-plus.git && cd ./cw-plus && cargo test | ||
``` | ||
|
||
You should see that everything in the repository gets compiled and all tests pass. | ||
|
||
The [`cw-plus`](https://github.com/CosmWasm/cw-plus) is a great place to find example contracts - | ||
look for them in the `contracts` directory. The repository is maintained by CosmWasm creators, so | ||
contracts in there should follow good practices. | ||
|
||
To verify the [`cosmwasm-check`](https://github.com/CosmWasm/cosmwasm/tree/main/packages/check) | ||
utility, first, you need to build a smart contract. Go to some contract directory, for example, | ||
`contracts/cw1-whitelist`, and call `cargo wasm`: | ||
|
||
```shell copy filename="TERMINAL" | ||
cd contracts/cw1-whitelist && cargo wasm | ||
``` | ||
|
||
<Callout> | ||
Due to reference types feature enabled by default in the Rust compiler since version `1.82` it is | ||
required to use the previous Rust compiler releases until the CosmWasm `2.2` version is released. | ||
The CosmWasm `2.2` will enable support for the reference types. | ||
</Callout> | ||
|
||
You should be able to find your output binary in the `target/wasm32-unknown-unknown/release/` of the | ||
root repo directory - not in the contract directory itself! Now you can check if contract validation | ||
passes: | ||
|
||
```shell copy filename="TERMINAL" | ||
cosmwasm-check ../../target/wasm32-unknown-unknown/release/ | ||
``` | ||
|
||
```shell | ||
cw-plus/contracts/cw1-whitelist $ cosmwasm-check | ||
../../target/wasm32-unknown-unknown/release/cw1_whitelist.wasm Available capabilities: {"iterator", | ||
"cosmwasm_1_1", "cosmwasm_1_2", "stargate", "staking"} | ||
|
||
../../target/wasm32-unknown-unknown/release/cw1_whitelist.wasm: pass | ||
|
||
All contracts (1) passed checks! | ||
``` |