Establish a connection to NextBlock's gRPC API using Tonic.
This page shows the connection pattern and authentication interceptor. Replace the placeholder generated client type with the client generated from nextblock-proto.
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"# Add your generated proto dependencies here# nextblock-proto = { path = "./generated" }
Connection Setup
Usage Example
Connection Best Practices
Use TLS in production: Always enable TLS for production environments
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Configure connection
let config = NextBlockConfig {
endpoint: "https://frankfurt.nextblock.io".to_string(),
api_key: "<your-api-key-here>".to_string(),
use_tls: true,
timeout: Duration::from_secs(30),
};
// Create authenticated client
let client = create_nextblock_client(config).await?;
// Use the client for API calls
// See other examples for specific usage patterns
println!("Successfully connected to NextBlock!");
Ok(())
}