This crate provides Sei specific bindings for cosmwasm contract to be able to interact with the Sei blockchain by exposing custom messages, queries, and structs that correspond to custom module functionality in the Sei chain.
Add the sei-cosmwasm dependency to your smart contract's Cargo.toml
file:
toml
[dependencies]
sei-cosmwasm = { version = "0.4.5" }
Currently, Sei Bindings support query and message support for the sei custom modules Oracle, Dex, Epoch and TokenFactory. The supported functionality includes the following:
factory/{creator address}/{subdenom}
given a subdenom
.To use these custom queries with the sei chain, you can create an instance of SeiQuerier
and call the query helper functions with the appropriate parameters.
rust
let querier = SeiQuerier::new(&deps.querier);
let res: ExchangeRatesResponse = querier.query_exchange_rates()?;
To use the custom messages, the messages need to be returned in the contract response to be executed by the sei chain.
rust
let test_order = sei_cosmwasm::SeiMsg::PlaceOrders {
contract_address: env.contract.address,
funds: vec![some_funds],
orders: vec![some_order],
};
Ok(Response::new().add_message(test_order))
The tokenfactory supports any Sei user to create, mint, burn and change owner of custom tokens.
```rust // create a new coin denom through the tokenfactory module. // This will create a denom with fullname "factory/{creator address}/{subdenom}" let testcreatedenom = seicosmwasm::SeiMsg::CreateDenom { subdenom: "subdenom".tostring(), }; Ok(Response::new().addmessage(testcreate_denom))
// mint a token and send to a designated receiver // note here the denom name provided must be the fullname in format of "factory/{creator address}/{subdenom}" let tokenfactorydenom = "factory/".tostring() + env.contract.address.tostring().asref() + "/subdenom"; let amount = coin(100, tokenfactory_denom);
let testmint = seicosmwasm::SeiMsg::MintTokens { amount: amount.toowned(), }; let sendmsg = SubMsg::new(BankMsg::Send { toaddress: info.sender.tostring(), amount: vec![amount], });
Ok(Response::new() .addmessage(testmint) .addsubmessage(sendmsg))
// burn a token, the denom name provided must be the fullname in format of "factory/{creator address}/{subdenom}" let tokenfactorydenom = "factory/".tostring() + env.contract.address.tostring().asref() + "/subdenom"; let amount = coin(10, tokenfactorydenom); let testburn = seicosmwasm::SeiMsg::BurnTokens { amount }; Ok(Response::new().addmessage(test_burn))
// change the owner of a token let tokenfactorydenom = "factory/".tostring() + env.contract.address.tostring().asref() + "/subdenom"; let newadminaddress = "${NEWADMINADDRESS}".tostring(); let testchangeadmin = seicosmwasm::SeiMsg::ChangeAdmin { denom: tokenfactorydenom, newadminaddress, }; Ok(Response::new().addmessage(testchangeadmin)) ```