#cosmwasm #cycle

cw-client

Rust library for interacting with CosmWasm-enabled blockchains. Deploy contracts, query them, and execute transactions.

7 releases (4 breaking)

0.5.1 Oct 14, 2025
0.5.0 Oct 8, 2025
0.4.0 Oct 2, 2025
0.3.1 Sep 11, 2025
0.1.0 Oct 16, 2024

#24 in #cycle

Download history 30/week @ 2025-10-27 38/week @ 2025-11-03 22/week @ 2025-11-10 91/week @ 2025-11-17 17/week @ 2025-11-24 34/week @ 2025-12-01 136/week @ 2025-12-08 82/week @ 2025-12-15 2/week @ 2025-12-22 10/week @ 2026-01-05 34/week @ 2026-01-12 24/week @ 2026-01-19 26/week @ 2026-01-26 53/week @ 2026-02-02 71/week @ 2026-02-09

175 downloads per month
Used in 3 crates (2 directly)

Apache-2.0

29KB
655 lines

cw-client

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.

Features

  • Query smart contracts
  • Execute transactions on smart contracts
  • Deploy new smart contracts
  • Query transaction details

Installation

Add this to your Cargo.toml:

[dependencies]
cw-client = { path = "crates/utils/cw-client", default-features = false }

Usage

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.

Querying a Smart Contract

let result: MyResponseType = client.query_smart(&contract_address, query_msg)?;

Executing a Transaction

let tx_hash = client.tx_execute(&contract_address, &chain_id, gas, &sender, execute_msg)?;

Deploying a New Contract

let contract_address = client.deploy(&chain_id, &sender, wasm_file_path)?;

Querying a Transaction

let tx_result: MyTxResultType = client.query_tx(&tx_hash)?;

Error Handling

The WasmdClient trait uses an associated Error type, allowing for flexible error handling depending on the specific implementation.

Development

To run tests:

cargo test

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under [LICENSE_NAME]. See the LICENSE file for details.

Dependencies

~31–48MB
~696K SLoC