This guide provides a comprehensive overview of creating, deploying, and interacting with CosmWasm contracts on a Wasm Minitia. It is essential to note that CosmWasm contracts are exclusively supported on Minitias utilizing the WasmVM.
Tutorial
Step 1: Clone the cw-contracts Repository
To begin, we will use the nameservice module from the cw-contracts repository as our example project. Execute the following commands to clone the repository and navigate to the relevant contract directory:
Use the command below to compile a Wasm binary, preparing it for deployment on a Wasm Minitia:
RUSTFLAGS='-C link-arg=-s'cargowasm
Upon successful compilation, the binary target/wasm32-unknown-unknown/release/cw_nameservice.wasm will be generated.
Advanced Compilation with rust-optimizer
For optimal efficiency, particularly in minimizing gas costs associated with deployment and interaction, the binary file size should be minimized. This necessitates the installation of Docker and the use of rust-optimizer, a tool designed to reduce the binary size without compromising contract functionality.
Execute the following command to utilize rust-optimizer:
The final step involves instantiating the newly stored contract. To achieve this, the codeId of the stored cw_nameservice.wasm contract is necessary. Fetch the codeId with the following command line:
Having successfully instantiated the CosmWasm contract, the next step involves interacting with it. This phase requires the contract's address, which can be retrieved using the command outlined below:
With the contract address at hand, we can now execute functions within the contract. As an example, we will execute the register function to register "test" as a name service domain. The execution command is as follows:
After the successful execution of the register function, verification of the registered name is achievable through a contract query. Utilize the following command to perform the query:
This step completes the guide on developing, deploying, and interacting with CosmWasm contracts. It illustrates the stages from contract compilation, storage, instantiation, to the final interaction phase. Following this guide ensures a structured approach to CosmWasm contract development, enabling developers to efficiently build and manage contracts within the Wasm Minitia.