An open API service indexing awesome lists of open source software.

https://github.com/casatrick/solana-block-engine-client

Rust client for Solana block engines - Rust library providing a consistent interface for interacting with multiple Solana block engine services. Features automatic region selection based on latency, built-in tip instruction generation, health monitoring, and performance metrics. Supports: Jito, Nozomi, ZeroSlot, BlockRazor, Astralane, NextBlock.
https://github.com/casatrick/solana-block-engine-client

astralane block-engine blockrazor jito nextblock nozomi rust solana zeroslot

Last synced: 29 days ago
JSON representation

Rust client for Solana block engines - Rust library providing a consistent interface for interacting with multiple Solana block engine services. Features automatic region selection based on latency, built-in tip instruction generation, health monitoring, and performance metrics. Supports: Jito, Nozomi, ZeroSlot, BlockRazor, Astralane, NextBlock.

Awesome Lists containing this project

README

          

# Block Engine JSON-RPC Client

A unified Rust client library for interacting with multiple Solana block engine services. This library provides a consistent interface for submitting transactions to various block engines including Jito, Nozomi, ZeroSlot, BlockRazor, Astralane, and NextBlock.

## Features

- **Multi-Engine Support**: Unified interface for 6 different Solana block engines
- **Automatic Region Selection**: Automatically selects the fastest region based on latency
- **High Performance**: Async/await architecture with optimized HTTP clients
- **Tip Management**: Built-in tip instruction generation for all supported services
- **Health Monitoring**: Health check functionality for service monitoring
- **Performance Metrics**: Built-in transaction submission timing

## Supported Services

| Service | API Key Required | Regions | Min Tip |
|---------|----------------|---------|---------|
| **Jito** | No (Optional) | 8 regions | 0.000001 SOL |
| **Nozomi** | Yes | Multiple | 0.001 SOL |
| **ZeroSlot** | Yes | Multiple | 0.001 SOL |
| **BlockRazor** | Yes | Multiple | 0.001 SOL |
| **Astralane** | Yes | Multiple | 0.0001/0.001 SOL |
| **NextBlock** | Yes | Multiple | 0.001 SOL |

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
solana-relayer-adapter-rust = "3.1.2"
```

Or install from git:

```toml
[dependencies]
solana-relayer-adapter-rust = { git = "https://github.com/your-repo/block-engine-json-rpc-client" }
```

## Configuration

Create a `.env` file in your project root with the required API keys:

```env
NOZOMI_API_KEY=your_nozomi_api_key
ZERO_SLOT_KEY=your_zero_slot_key
BLOCKRAZOR_API_KEY=your_blockrazor_key
ASTRALANE_API_KEY=your_astralane_key
NEXTBLOCK_API_KEY=your_nextblock_key
```

**Note**: Jito does not require an API key.

## Usage

### Basic Example

```rust
use solana_relayer_adapter_rust::{Jito, Tips};
use solana_sdk::{pubkey::Pubkey, instruction::Instruction};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize Jito client (auto-selects fastest region)
let jito = Jito::new_auto(None).await;

// Create tip configuration
let tip_config = Tips {
tip_sol_amount: 0.001,
tip_addr_idx: 0,
cu: Some(200_000),
priority_fee_micro_lamport: Some(1000),
payer: Pubkey::new_unique(),
pure_ix: vec![], // Your instructions here
};

// Generate tip instructions
let instructions = jito.add_tip_ix(tip_config);

// Build and sign your transaction...
// let transaction = Transaction::new_with_payer(&instructions, &Some(payer_pubkey));
// let encoded_tx = base64::encode(transaction.serialize()?);

// Submit transaction
// let response = jito.send_transaction(&encoded_tx).await?;

Ok(())
}
```

### Initialize All Services

```rust
use solana_relayer_adapter_rust::{Astralane, BlockRazor, Jito, NextBlock, Nozomi, ZeroSlot};
use dotenvy::dotenv;
use std::env;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv().ok();

// Initialize Jito (no API key required)
let jito = Jito::new_auto(None).await;

// Initialize other services (API key required)
let nozomi = Nozomi::new_auto(
env::var("NOZOMI_API_KEY")?
).await;

let zero_slot = ZeroSlot::new_auto(
env::var("ZERO_SLOT_KEY")?
).await;

let blockrazor = BlockRazor::new_auto(
env::var("BLOCKRAZOR_API_KEY")?
).await;

let astralane = Astralane::new_auto(
env::var("ASTRALANE_API_KEY")?
).await;

let nextblock = NextBlock::new_auto(
env::var("NEXTBLOCK_API_KEY")?
).await;

Ok(())
}
```

### Manual Region Selection

```rust
use solana_relayer_adapter_rust::{Jito, JitoRegionsType};

let jito = Jito::new_with_region(
JitoRegionsType::NY,
None
).await;
```

### Health Monitoring

```rust
// Start health check (runs in background)
jito.health_check(50); // Check every 50 seconds
```

## API Reference

### Client Methods

#### `new_auto(auth_key)`
Automatically selects the fastest region by pinging all available regions.

- **Jito**: `new_auto(Option)`
- **Others**: `new_auto(String)`

#### `new_with_region(region, auth_key)`
Initialize client with a specific region.

#### `add_tip_ix(tip_config: Tips) -> Vec`
Generates Solana instructions for tipping the block engine, including:
- Compute unit limit (if specified)
- Priority fee (if specified)
- Your custom instructions
- Tip transfer instruction

#### `send_transaction(encoded_tx: &str) -> Result`
Submits a base64-encoded transaction to the block engine via JSON-RPC.

#### `health_check(interval_sec: u64)`
Starts a background health check task that monitors the service.

### Types

#### `Tips`
```rust
pub struct Tips {
pub tip_sol_amount: f64,
pub tip_addr_idx: u8,
pub cu: Option,
pub priority_fee_micro_lamport: Option,
pub payer: Pubkey,
pub pure_ix: Vec,
}
```

## Architecture

The library is organized into service-specific modules, each following a consistent pattern:

- `*_confirm.rs` - Main client implementation
- `*_regions.rs` - Regional endpoint configuration
- `*_tip_ix.rs` - Tip recipient addresses and minimums

All services implement:
- Automatic region selection via latency-based ping
- JSON-RPC 2.0 transaction submission
- Tip instruction generation
- Health monitoring capabilities

## Dependencies

- `tokio` - Async runtime
- `reqwest` - HTTP client
- `solana-sdk` / `solana-program` - Solana blockchain integration
- `serde_json` - JSON serialization
- `anyhow` - Error handling
- `ping` - ICMP ping for latency measurement

## License

Licensed under the MIT License. See [LICENSE-MIT](LICENSE-MIT) for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Version

Current version: **3.1.2**