This repo provides comprehensive guide for integrating the CosmWasm module to chains scaffolded with Ignite CLI, enabling you to explore and test smart contract functionalities.
To start your own CosmWasm chain, you have to scaffold a chain with Ignite CLI.
- Install Ignite CLI:
$ curl https://get.ignite.com/cli! | bash
- Scaffold a chain
$ ignite scaffold chain planet
$ cd planet
- Import wasm module
$ go get github.com/CosmWasm/wasmd/x/wasm@v0.41.0
- Integrate wasm module
Follow the changes in the commit: https://github.com/yerasyla/IgniteCLI-cosmwasm/commit/f698ff35c544428f75d747787dcb4447a82d6752
Instructions:
a. Create an app/ante.go
and app/wasm.go
files and copy the content
b. Modify app/app.go
file
c. Modify app/simulation_test.go
, cmd/planetd/cmd/root.go
, and testutil/network/network.go
You should have working CosmWasm chain at that point
- Launch your chain
$ ignite chain serve
serve
command installs dependencies, builds, initializes, and starts your blockchain in development.
Testing CosmWasm smart-contract capabilities in your chain, can be performed by following these steps:
$ ignite chain serve
- Prepare cosmwasm smart-contract for deployment
$ git clone https://github.com/CosmWasm/cw-examples
$ cd cw-examples
$ cd contracts/nameservice
$ cargo wasm
Optimize contract to reduce gas
$ 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/rust-optimizer:0.12.12
For ARM64 machines:
$ 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/rust-optimizer-arm64:0.12.12
- Deploy smart-contract to your chain
$ planetd tx wasm store artifacts/cw_nameservice.wasm --from alice --gas=10000000
- Check your smart-contract on chain
$ planetd query wasm list-code
code_infos:
- code_id: "1"
creator: cosmos1a4w3vwxa8zhy57nyy9kw7zhdasr4ue4wld0zpn
data_hash: DF3C9BC1341322810523AABCA28CC3FCDCA021C85061743967CE3D20F5580093
pagination: {}
# download wasm and diff with origin
$ CODE_ID=$(planetd query wasm list-code --output json | jq -r '.code_infos[0].code_id')
$ planetd query wasm code $CODE_ID download.wasm
$ diff artifacts/cw_nameservice.wasm download.wasm
- Instantiate smart-contract, in CosmWasm deployment and instantiation are 2 different steps
$ INIT='{"purchase_price":{"amount":"100","denom":"stake"},"transfer_price":{"amount":"999","denom":"stake"}}'
$ planetd tx wasm instantiate 1 "$INIT" --from alice --chain-id "planet" --label "awesome name service" --no-admin
$ CONTRACT=$(planetd query wasm list-contract-by-code $CODE_ID --output json | jq -r '.contracts[-1]')
# check contract state (you should get contract address)
$ planetd query wasm contract $CONTRACT
address: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d
contract_info:
code_id: "1"
creator: cosmos1a4w3vwxa8zhy57nyy9kw7zhdasr4ue4wld0zpn
label: awesome name service
- Interact with smart-contract
# purchase name
$ planetd tx wasm execute $CONTRACT '{"register":{"name":"test"}}' --amount 100stake --from alice $TXFLAG -y
# query registered name (you should see your address as owner of the name)
$ NAME_QUERY='{"resolve_record": {"name": "test"}}'
$ planetd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --output json
Ignite CLI | Cosmos SDK | IBC | wasmd |
---|---|---|---|
v0.27.1 | v0.47.4 | v7.2.0 | v0.41.0 |