| Crates.io | cw-client |
| lib.rs | cw-client |
| version | 0.3.1 |
| created_at | 2024-10-16 19:22:46.570304+00 |
| updated_at | 2025-09-11 16:54:42.840417+00 |
| description | Rust library for interacting with CosmWasm-enabled blockchains. Deploy contracts, query them, and execute transactions. |
| homepage | https://cycles.money |
| repository | https://github.com/informalsystems/cycles-quartz |
| max_upload_size | |
| id | 1412229 |
| size | 78,989 |
cw-client is a Rust library that provides a trait and implementation for interacting with CosmWasm-enabled blockchains, specifically designed for use with the wasmd daemon.
Add this to your Cargo.toml:
[dependencies]
cw-client = { path = "crates/utils/cw-client", default-features = false }
The main interface is provided through the WasmdClient trait:
pub trait WasmdClient {
type Address: AsRef<str>;
type Query: ToString;
type RawQuery: ToHex;
type ChainId: AsRef<str>;
type Error;
fn query_smart<R: DeserializeOwned>(
&self,
contract: &Self::Address,
query: Self::Query,
) -> Result<R, Self::Error>;
fn query_raw<R: DeserializeOwned + Default>(
&self,
contract: &Self::Address,
query: Self::RawQuery,
) -> Result<R, Self::Error>;
fn query_tx<R: DeserializeOwned + Default>(&self, txhash: &str) -> Result<R, Self::Error>;
fn tx_execute<M: ToString>(
&self,
contract: &Self::Address,
chain_id: &Id,
gas: u64,
sender: &str,
msg: M,
) -> Result<String, Self::Error>;
fn deploy<M: ToString>(
&self,
chain_id: &Id,
sender: &str, // what should this type be
wasm_path: M,
) -> Result<String, Self::Error>;
To use the client, implement this trait for your specific needs or use the provided implementation.
let result: MyResponseType = client.query_smart(&contract_address, query_msg)?;
let tx_hash = client.tx_execute(&contract_address, &chain_id, gas, &sender, execute_msg)?;
let contract_address = client.deploy(&chain_id, &sender, wasm_file_path)?;
let tx_result: MyTxResultType = client.query_tx(&tx_hash)?;
The WasmdClient trait uses an associated Error type, allowing for flexible error handling depending on the specific implementation.
To run tests:
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under [LICENSE_NAME]. See the LICENSE file for details.