Rust Example
Complete Rust implementation for streaming Solana transactions from NextBlock's TX Stream API using Tonic.
The example is hosted at github.com/nextblock-ag/nextblock-stream-examples
Prerequisites
Add these dependencies to your Cargo.toml:
[package]
name = "rust-example"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.99"
bincode = "1.3.3"
bs58 = "0.5"
prost = "0.13"
prost-types = "0.13"
protobuf = "3.7.2"
rand = "0.8"
solana-sdk = "3.0.0"
time = "0.3"
tokio = { version = "1.39", features = ["rt-multi-thread", "macros"] }
tonic = { version = "0.12", features = ["gzip"] }
[build-dependencies]
tonic-build = "0.12"Proto build script build.rs
Example
Usage Examples
Available Endpoints
Choose the endpoint closest to your location:
Frankfurt:
fra.stream.nextblock.io:22221Amsterdam:
amsterdam.stream.nextblock.io:22221London:
london.stream.nextblock.io:22221Singapore:
singapore.stream.nextblock.io:22221Tokyo:
tokyo.stream.nextblock.io:22221New York:
ny.stream.nextblock.io:22221Salt Lake City:
slc.stream.nextblock.io:22221Dublin:
dublin.stream.nextblock.io:22221Vilnius:
vilnius.stream.nextblock.io:22221
Best Practices
Match the endpoint requirements: Follow the transport settings shown in the example for the current TX Stream service
Filter efficiently: Only subscribe to programs you need to reduce bandwidth
Handle reconnections: Implement automatic reconnection logic
Process quickly: Avoid blocking the stream receiver
Monitor performance: Track processing latency and throughput
Implement graceful shutdown: Handle interrupt signals properly
Use multiple endpoints: Implement redundancy for critical applications
Last updated