A Rust client library for interacting with CosmWasm-enabled blockchain networks. This library provides a simple and efficient way to perform operations like contract deployment, message execution, and event listening on CosmWasm chains.
- Contract Operations: Deploy, instantiate and execute CosmWasm smart contracts
- Event Listening: Subscribe to and process blockchain events
- Wallet Management: Handle blockchain accounts and transactions
- Chain Interaction: Communicate with the blockchain through gRPC and WebSocket
- Type-safe Interface: Leverage Rust's type system for safe contract interactions
- Rust 2021 edition or later
- A running CosmWasm-compatible blockchain node
- Access to both gRPC and WebSocket endpoints of the blockchain node
Add this to your Cargo.toml
:
[dependencies]
cosmwasm-client-rs = "0.1.0"
Here's a basic example of how to use the client:
use cosmwasm_client_rs::CosmWasmClient;
use cosmrs::AccountId;
use std::str::FromStr;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize client
let grpc_url = "http://localhost:9090";
let ws_url = "ws://localhost:26657/websocket";
let private_key = "your_private_key";
let contract = AccountId::from_str("your_contract_address")?;
let client = CosmWasmClient::new(grpc_url, ws_url, private_key, Some(contract))
.await?;
// Perform operations
// ... your code here ...
Ok(())
}
Check the examples
directory for more detailed usage examples.
The repository includes several examples demonstrating different features:
contract_operations.rs
: Shows how to perform contract operationsevent_listener.rs
: Demonstrates event subscription and handling
Key dependencies include:
cosmos-sdk-proto
: For blockchain communicationtendermint-rpc
: For RPC interactionscosmrs
: For CosmWasm operationstokio
: For async runtimetonic
: For gRPC support
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This software is in active development. Please use it carefully in production environments.