Rust
Complete Rust examples for integrating with NextBlock's gRPC API using Tonic and the Solana SDK.
Overview
These examples demonstrate how to:
Establish secure gRPC connections with authentication
Submit single and batched transactions with proper tipping
Stream real-time tip floor data for dynamic tip optimization
Maintain persistent connections with keepalive mechanisms
Prerequisites
Add these dependencies to your Cargo.toml
:
[dependencies]
tonic = "0.10"
tokio = { version = "1.0", features = ["full"] }
solana-sdk = "1.17"
solana-client = "1.17"
base64 = "0.21"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rand = "0.8"
chrono = { version = "0.4", features = ["serde"] }
once_cell = "1.19"
# Add your generated proto dependencies here
# nextblock-proto = { path = "./generated" }
Examples
Core Examples
Connection - Establish gRPC connections with authentication
Submit Single Transaction - Send individual transactions with tips
Submit Batched Transactions - Send atomic transaction bundles
Tip Floor Stream - Stream real-time tip floor data
Keepalive - Maintain persistent connections
Quick Start
Generate gRPC client from nextblock-proto
Set up your environment with API key and endpoint
Start with connection example to establish authenticated gRPC connection
Use tip floor streaming to optimize transaction tips dynamically
Submit transactions using single or batched submission methods
Key Features
Authentication
All examples include proper API key authentication using Tonic's interceptor pattern.
Error Handling
Comprehensive error handling with retry logic and graceful degradation.
Connection Management
Persistent connections with keepalive, health monitoring, and automatic recovery.
Dynamic Tipping
Real-time tip optimization based on current network conditions from tip floor API.
Transaction Building
Complete transaction building with Solana SDK integration and proper signing.
Best Practices
Use TLS in production - Always enable TLS for production environments
Implement keepalive - Maintain persistent connections for better performance
Monitor tip floors - Use streaming API to adjust tips dynamically
Handle errors gracefully - Implement proper retry logic with exponential backoff
Validate inputs - Always validate public keys and transaction parameters
Use appropriate endpoints - Choose the endpoint closest to your location
Last updated