For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:22221

  • Amsterdam: amsterdam.stream.nextblock.io:22221

  • London: london.stream.nextblock.io:22221

  • Singapore: singapore.stream.nextblock.io:22221

  • Tokyo: tokyo.stream.nextblock.io:22221

  • New York: ny.stream.nextblock.io:22221

  • Salt Lake City: slc.stream.nextblock.io:22221

  • Dublin: dublin.stream.nextblock.io:22221

  • Vilnius: vilnius.stream.nextblock.io:22221

Best Practices

  1. Match the endpoint requirements: Follow the transport settings shown in the example for the current TX Stream service

  2. Filter efficiently: Only subscribe to programs you need to reduce bandwidth

  3. Handle reconnections: Implement automatic reconnection logic

  4. Process quickly: Avoid blocking the stream receiver

  5. Monitor performance: Track processing latency and throughput

  6. Implement graceful shutdown: Handle interrupt signals properly

  7. Use multiple endpoints: Implement redundancy for critical applications

Last updated