While writing smart contracts is a huge topic in itself, for the purposes of this tutorial we're going to use one of the many examples provided by cosmwasm.
Use the following commands to clone the repository with needed code:
git clone https://github.com/CosmWasm/cw-plus.git
# get the code
git clone https://github.com/InterWasm/cw-contracts
git checkout main
One of options is to compile the contract with rust stable toolchain.
rustup default stable
After the compilation is finished, you should be able to find a file in
target/wasm32-unknown-unknown/release/cw_nameservice.wasm. It will be about 1.7mb (you can check the size with
ls -lh command).
You can get much smaller version, with thee following command. It instructs the compiler to discard all unused code:
`RUSTFLAGS='-C link-arg=-s' cargo wasm
The resulting file about 165kB big. This helps to limit gas usage substantially.
You can now upload the contract to the chain.
RES=$(iond tx wasm store cw_nameservice.wasm --from wallet1 $TXFLAGS -y --output json -b block)
You can find the contracts code in output of the above command, but it is simpler to use following command:
CODE_ID=$(echo $RES | jq -r '.logs.events[-1].attributes.value')
As there are no contracts yet, this should return an empty list:
iond query wasm list-contract-by-code $CODE_ID --output json