The wasm bindings for building CosmWasm smart contracts that can run on the Router chain.
Before starting, make sure you have rustup along with a
recent rustc
and cargo
version installed. Currently, we are testing on 1.62.1+.
And you need to have the wasm32-unknown-unknown
target installed as well.
You can check that via:
```sh rustc --version cargo --version rustup target list --installed
rustup target add wasm32-unknown-unknown ```
On the Router chain, We can build two types of contracts. - Contracts that are not interacting with cross-chain contracts. - Contracts that are back and forth sending the data request to cross-chain contracts.
To build second type of contracts that are interacting with other chains, the user/ applications needs to implement router-wasm-binding crate.
```sh
router-wasm-bindings = "0.1.2" ```
To implement cross-chain interoperability, the contract needs to implement the following functionality - SudoMsg for handling incoming requests from the other chains - RouterMsg to send request to the other chains.
The Contract can write the intermediate business logic inbetween of the incoming request and outbound request. While writing the intermediate business logic, the developer can combine single or multiple incoming request into single or multiple outbound request.
Also, while creating request to other chain, the contract can be developed in such a way where mutiple request can be generated to different chains.
You can find examples for different scenarios in the cw-bridge-contracts repository.
The sudo function is one of the entry point for a router-bridge-contract. It can be called internally by the chain only. It needs to implement to receive incoming request from the other chains. ```sh
use routerwasmbindings::{RouterMsg, SudoMsg};
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> StdResult
```
The RouterMsg is a enum type of the entry point for a router-bridge-contract. It can be called internally by the chain only. It needs to implement to receive incoming request from the other chains. ```sh
use routerwasmbindings::{RouterMsg, SudoMsg};
let address: String = String::from("destinationcontractaddress");
let payload: Vec
let contractcall: ContractCall = ContractCall { destinationcontractaddress: address.clone().intobytes(), payload, }; let outboundbatchreq: OutboundBatchRequest = OutboundBatchRequest { destinationchaintype: ChainType::ChainTypeEvm.getchaincode(), destinationchainid: String::from("137"), contractcalls: vec![contractcall], relayerfee: Coin { denom: String::from("router"), amount: Uint128::new(8u128), }, outgoingtxfee: Coin { denom: String::from("router"), amount: Uint128::new(8u128), }, isatomic: false, exptimestamp: None, }; let outboundbatchreqs: RouterMsg = RouterMsg::OutboundBatchRequests { outboundbatchrequests: vec![outboundbatchreq], issequenced: false, };
let res = Response::new() .addmessage(outboundbatch_reqs); Ok(res)
```