Rust
Official Rust client library for ThorStreamer with async/await support.
Installation
Add to Cargo.toml:
[dependencies]
thorstreamer-grpc-client = "0.1"
tokio = { version = "1", features = ["full"] }Quick Start
use thorstreamer_grpc_client::{ClientConfig, ThorClient, parse_message};
use thorstreamer_grpc_client::proto::thor_streamer::types::message_wrapper::EventMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig {
server_addr: "http://your-server:50051".to_string(),
token: "your-token".to_string(),
..Default::default()
};
let mut client = ThorClient::new(config).await?;
let mut stream = client.subscribe_to_transactions().await?;
while let Some(response) = stream.message().await? {
let msg = parse_message(&response.data)?;
if let Some(EventMessage::Transaction(tx_wrapper)) = msg.event_message {
if let Some(tx) = tx_wrapper.transaction {
println!("Transaction: slot={}", tx.slot);
}
}
}
Ok(())
}API Reference
Creating a Client
subscribe_to_transactions
subscribe_to_slot_status
subscribe_to_wallet_transactions
Monitor up to 10 wallet addresses:
subscribe_to_account_updates
Monitor accounts with optional owner filtering:
Error Handling
Environment Variables
Using dotenv:
Full Example
See the complete implementation in the examples directory: https://github.com/thorlabsDev/ThorStreamer/tree/master/examples/rust
Resources
Last updated