ucs03-zkgm Asset Transfer Tutorial - CosmWasm
Prerequisites
This tutorial assumes that you have experience creating contracts in CosmWasm. If you need to familiarize yourself with CosmWasm, you should start with the CosmWasm book and the other resources listed by the CosmWasm team.
The Union team uses Nix to manage developer environments. While this tutorial may mention different developer tools, it will not guide you through setting each one up.
This tutorial will assume that you have a working rust tool chain, including cargo
.
You will also need a chain that supports CosmWasm running where you plan to deploy ucs03 and your app. This tutorial will assume you are deploying your contract on union-testnet-9
.
Users will need to find a valid RPC node to use as RPC_URL
throughout the tutorial.
Tutorial
- Write your contract
- Deploy your contract
- Example transfer
Write Your Contract
To demonstrate asset transfers with ucs03, this tutorial will walk you through creating a simple contract that sends a single token.
Project Bootstrapping
If you don’t already have a project folder for your contract, make one now and navigate inside.
Add required dependencies to the Cargo.toml
file.
Below is a sample contract that can be pasted into lib.rs
.
This contract exposes the transfer message from ucs03-zkgm (Ucs03ExecuteMsg
), then sends that message to the deployed ucs03-zkgm. To see all the messages exposed by ucs03-zkgm, refer to the contract in our repository
Building the Contract
With this contract code ready, the WASM blob can be built.
The contract can now be deployed.
Deploying your Contract
With the WASM blob ready, the contract can be deployed.
Be sure to copy the CODE_ID
of the newly stored code. Using the previous transaction hash, you can see it by running this command:
Next, submit a transaction to instantiate the contract. Copy the value of the NEW transaction hash into a shell variable (TX_HASH
).
You can then get the contract address by running:
Example Transfer
With the address of your contract in hand, a sample transfer can now be conducted.
First, prepare a payload.json
that will hold the main message of the transfer.
This will send UNO to a Holesky address of your choice
The message can then be sent to the contract for execution.