### Full Configuration Setup Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md A complete example demonstrating how to initialize tracing, load configuration from environment variables, create the SDK instance, and fetch tip accounts. ```rust use jito_sdk_rust::JitoJsonRpcSDK; use tracing_subscriber::EnvFilter; fn init_tracing() { tracing_subscriber::fmt() .with_env_filter( EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info")) ) .init(); } struct Config { block_engine_url: String, jito_uuid: Option, network: String, } impl Config { fn from_env() -> Self { Config { block_engine_url: std::env::var("BLOCK_ENGINE_URL") .unwrap_or_else(|_| "https://mainnet.block-engine.jito.wtf/api/v1".to_string()), jito_uuid: std::env::var("JITO_UUID").ok(), network: std::env::var("NETWORK").unwrap_or_else(|_| "mainnet".to_string()), } } fn create_sdk(&self) -> JitoJsonRpcSDK { JitoJsonRpcSDK::new(&self.block_engine_url, self.jito_uuid.clone()) } } #[tokio::main] async fn main() -> Result<(), Box> { init_tracing(); let config = Config::from_env(); let sdk = config.create_sdk(); let tip_accounts = sdk.get_tip_accounts().await?; println!("Tip accounts: {}", JitoJsonRpcSDK::prettify(tip_accounts)); Ok(()) } ``` -------------------------------- ### Basic Transaction Example Setup Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/README.md Load the sender's keypair from a file and set up the receiver's public key for a basic transaction. ```rust use jito_sdk_rust::keypair::Keypair; use solana_sdk::pubkey::Pubkey; use std::str::FromStr; // Load the sender's keypair let sender = Keypair::read_from_file("/path/to/wallet.json") .expect("Failed to read wallet file"); // Set up receiver pubkey let receiver = Pubkey::from_str("YOUR_RECEIVER_PUBKEY")?; ``` -------------------------------- ### Async Runtime Setup Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md All SDK methods are async and require an async context. This example shows how to use `tokio::main` to establish such a context for calling SDK methods. ```rust #[tokio::main] async fn main() { let response = sdk.get_tip_accounts().await?; } ``` -------------------------------- ### Example Environment Setup for Application Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Demonstrates setting the RUST_LOG environment variable and then running a Cargo application. This is useful for controlling application logging during development or execution. ```bash # Set logging level export RUST_LOG=debug # Run application cargo run --example basic_usage ``` -------------------------------- ### Run Basic Bundle Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/README.md Execute the basic bundle example using Cargo. ```bash cargo run --example basic_bundle ``` -------------------------------- ### Environment Variable Configuration Usage Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Shows how to run the full configuration setup example using different environment variables for customization, including setting a UUID, enabling debug logging, and specifying a custom endpoint. ```bash # Development # cargo run # Production with UUID # JITO_UUID=550e8400-e29b-41d4-a716-446655440000 cargo run # Debug logging # RUST_LOG=debug cargo run # Custom endpoint # BLOCK_ENGINE_URL=http://localhost:8080/api/v1 cargo run ``` -------------------------------- ### Initialize SDK and Get Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Initializes the Jito SDK with a network URL and fetches the available tip accounts. This is a common starting point for interacting with the Jito network. ```rust use jito_sdk_rust::JitoJsonRpcSDK; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize SDK let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", None ); // Get tip accounts let tip_accounts = sdk.get_tip_accounts().await?; println!("{}", JitoJsonRpcSDK::prettify(tip_accounts)); Ok(()) } ``` -------------------------------- ### Install Rust Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/README.md Install Rust using the official script. Verify the installation and keep it updated. ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` ```bash rustc --version ``` ```bash rustup update ``` -------------------------------- ### Run Basic Transaction Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/README.md Execute the basic transaction example using Cargo. ```bash cargo run --example basic_txn ``` -------------------------------- ### Async Runtime Setup with Tokio Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Applications using the SDK must be set up as async. This snippet shows the basic setup using `#[tokio::main]` and an alternative with custom Tokio configuration. ```rust #[tokio::main] async fn main() { // All SDK calls must be within async context } ``` ```rust #[tokio::main(flavor = "multi_thread", worker_threads = 4)] async fn main() { // ... } ``` -------------------------------- ### Minimal Jito Rust RPC SDK Configuration Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Initialize the SDK with a connection URL. This is the most basic setup. ```rust let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", None); ``` -------------------------------- ### Example JSON-RPC Request for getTipAccounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/types.md A specific example of a JSON-RPC request for the getTipAccounts method, which takes no parameters. ```json { "jsonrpc": "2.0", "id": 1, "method": "getTipAccounts", "params": [] } ``` -------------------------------- ### Get Tip Accounts Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md An example of a successful response from the getTipAccounts endpoint. The result field contains an array of base58-encoded public keys for tip accounts. A 200 OK status code indicates success. ```json { "jsonrpc": "2.0", "id": 1, "result": [ "96gYZGLnJYVFmbjzopPSU6QiEV5nWosSjkwTLrmpuCe", "HFqU5x63VQ2AWYkCRg7qWStEFYpFADecZcqto4C6XV24", "ADaUMid9yfLsghCkrqRb69vDmisTbS16yTc6nchvx55" ] } ``` -------------------------------- ### Initialize Jito SDK Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Basic initialization of the JitoJsonRpcSDK with a connection URL. This is the simplest way to start using the SDK. ```rust use jito_sdk_rust::JitoJsonRpcSDK; #[tokio::main] async fn main() -> Result<(), Box> { let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", None ); // Use the SDK let tip_accounts = sdk.get_tip_accounts().await?; println!("{:?}", tip_accounts); Ok(()) } ``` -------------------------------- ### getBundleStatuses Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md Example JSON response from the getBundleStatuses RPC method, showing the confirmation status of a bundle. ```json { "jsonrpc": "2.0", "id": 1, "result": { "value": [ { "bundle_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "transactions": [ "5sKpMxUsKqbDvKJmJVahh9gM9eHSFZ9K3wazKKUJQVbX4Y9xnJxKKkMVfBF7NRV6" ], "confirmation_status": "finalized", "err": { "Ok": null } } ] } } ``` -------------------------------- ### Example JSON-RPC Request for sendBundle Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/types.md An example of a JSON-RPC request for the sendBundle method, demonstrating parameter structure for transactions and encoding. ```json { "jsonrpc": "2.0", "id": 1, "method": "sendBundle", "params": [ ["base64-encoded-tx1", "base64-encoded-tx2"], {"encoding": "base64"} ] } ``` -------------------------------- ### Submit and Confirm Jito Bundle Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md This example shows the complete flow for submitting a bundle of transactions to Jito and then polling for its status until it is landed and finalized. It includes steps for submitting the bundle, checking its in-flight status, and finally confirming its finalization. ```rust #[tokio::main] async fn submit_and_confirm_bundle( sdk: &JitoJsonRpcSDK, transactions: Vec, ) -> Result<()> { // Step 1: Submit let params = json!(transactions); let response = sdk.send_bundle(Some(params), None).await?; let bundle_uuid = response["result"].as_str().unwrap(); println!("Submitted: {}", bundle_uuid); // Step 2: Poll in-flight status loop { let status = sdk.get_in_flight_bundle_statuses( vec![bundle_uuid.to_string()] ).await?; match status["result"]["value"][0]["status"].as_str() { Some("Landed") => break, Some("Pending") => { sleep(Duration::from_secs(1)).await }, Some("Failed") => return Err("Bundle failed".into()), _ => {} // Handle other statuses or unexpected responses } } // Step 3: Poll confirmation status loop { let status = sdk.get_bundle_statuses( vec![bundle_uuid.to_string()] ).await?; match status["result"]["value"][0]["confirmation_status"].as_str() { Some("finalized") => return Ok(()), Some("confirmed") => { sleep(Duration::from_secs(1)).await }, _ => {} // Handle other statuses or unexpected responses } } } ``` -------------------------------- ### Implementing Structured Logging for Bundles Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/errors.md This example demonstrates structured logging for bundle submission results using the `tracing` crate. It logs success, validation failures, and other submission errors with different log levels. ```rust use tracing::{error, warn, info}; match sdk.send_bundle(params, None).await { Ok(response) => { info!("Bundle submitted successfully"); }, Err(e) if e.to_string().contains("at most 5") => { error!("Validation failed: {}", e); }, Err(e) => { warn!("Bundle submission failed, will retry: {}", e); } } ``` -------------------------------- ### Safe Unwrapping Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Demonstrates how to safely unwrap optional values from a JSON response instead of using `unwrap()`, which can cause panics. This example shows using `ok_or_else` for robust error handling. ```rust // Instead of unwrap() which panics: let uuid = response["result"].as_str().unwrap(); // Dangerous! // Use proper error handling: let uuid = response["result"] .as_str() .ok_or_else(|| anyhow!("No UUID in response"))? // This line requires the `anyhow` crate .to_string(); ``` -------------------------------- ### prettify() Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Formats data for display. Includes usage examples. ```APIDOC ## prettify() ### Description A utility function to format data into a more human-readable string. This is useful for debugging and display purposes. ### Method `prettify(data: &serde_json::Value) -> String` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let json_data = serde_json::json!({"key": "value"}); let pretty_string = client.prettify(&json_data); println!("{}", pretty_string); ``` ### Response #### Success Response A string representation of the input data, formatted for readability. #### Response Example ```json { "key": "value" } ``` ``` -------------------------------- ### getBundleStatuses Request Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md Example JSON payload for the getBundleStatuses RPC method. It includes a list of bundle UUIDs to query. ```json { "jsonrpc": "2.0", "id": 1, "method": "getBundleStatuses", "params": [ [ "f47ac10b-58cc-4372-a567-0e02b2c3d479", "a12b3c4d-1234-5678-abcd-ef0123456789" ] ] } ``` -------------------------------- ### Send Transaction Request Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This is an example of a JSON-RPC request to send a transaction. Ensure the transaction is base64-encoded and include options like skipPreflight if needed. ```json { "jsonrpc": "2.0", "id": 1, "method": "sendTransaction", "params": [ "AgA9f7x3T...base64-encoded-transaction...", { "encoding": "base64", "skipPreflight": false } ] } ``` -------------------------------- ### Async Call to Get Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/api-reference.md Demonstrates how to make an asynchronous call to the `get_tip_accounts` method using the Jito Rust RPC SDK. Ensure you are in an async context, such as within a `#[tokio::main]` function. ```rust #[tokio::main] async fn main() -> Result<()> { let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", None); let response = sdk.get_tip_accounts().await?; Ok(()) } ``` -------------------------------- ### Integration Test for Get Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md An integration test to verify the `get_tip_accounts` method. It initializes the SDK and asserts that the response is a JSON array. ```rust #[tokio::test] async fn test_get_tip_accounts() -> Result<() { let sdk = JitoJsonRpcSDK::new( "https://testnet.block-engine.jito.wtf/api/v1", None ); let response = sdk.get_tip_accounts().await?; assert!(response["result"].is_array()); Ok(()) } ``` -------------------------------- ### Handle `get_tip_accounts()` Errors in Rust Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/errors.md This example shows how to handle potential network errors and RPC-specific errors returned within the JSON response from the `get_tip_accounts` method. ```rust match sdk.get_tip_accounts().await { Ok(response) => { if let Some(error) = response.get("error") { eprintln!("RPC Error: {:?}", error); } else if let Some(result) = response.get("result") { println!("Tip accounts: {:?}", result); } }, Err(e) => { eprintln!("Network error: {}", e); // Implement exponential backoff retry } } ``` -------------------------------- ### Submit Transaction with Preflight Check Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md This example shows how to submit a serialized transaction using the SDK, with the option to enable or disable preflight checks. Setting `skipPreflight` to `false` ensures that the transaction undergoes validation before being processed. ```rust let params = json!({"tx": serialized_tx, "skipPreflight": false}); let response = sdk.send_txn(Some(params), false).await?; let signature = response["result"].as_str().unwrap(); ``` -------------------------------- ### sendBundle Request Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This JSON object demonstrates the structure of a request to the sendBundle method. It includes an array of base64-encoded transactions and an options object specifying the encoding. ```json { "jsonrpc": "2.0", "id": 1, "method": "sendBundle", "params": [ [ "AgA9f7x3T...base64-encoded-transaction...", "AgB4f8x3T...another-base64-transaction..." ], { "encoding": "base64" } ] } ``` -------------------------------- ### getInflightBundleStatuses Request Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This JSON object demonstrates the structure for requesting the in-flight status of bundles using their UUIDs. ```json { "jsonrpc": "2.0", "id": 1, "method": "getInflightBundleStatuses", "params": [ [ "f47ac10b-58cc-4372-a567-0e02b2c3d479" ] ] } ``` -------------------------------- ### Unit Test with Mock Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Example of a unit test for bundle validation. In a real scenario, you would mock the HTTP response instead of making an actual SDK call. ```rust #[cfg(test)] mod tests { use super::*; #[test] fn test_bundle_validation() { let large_bundle = vec!["tx".to_string(); 10]; // This would fail if SDK was actually called // In real code, you'd mock the HTTP response } } ``` -------------------------------- ### Safe Handling of RPC Responses Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Provides an example of how to safely parse and handle JSON-RPC responses, first checking for RPC errors and then accessing the result field. ```rust // Check for RPC error first if let Some(error) = response.get("error") { eprintln!("RPC Error: {}", error["message"]); return Err("RPC error".into()); } // Access result field let result = response["result"].as_str().unwrap_or(""); ``` -------------------------------- ### Handle SDK Errors Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/api-reference.md Handle potential `anyhow::Error` for logical issues and `reqwest::Error` for network problems when interacting with the SDK. This example shows how to process successful responses or catch and report errors. ```rust match sdk.send_bundle(Some(params), None).await { Ok(response) => { let uuid = response["result"].as_str().unwrap(); println!("Bundle sent: {}", uuid); }, Err(e) => { eprintln!("Failed to send bundle: {}", e); // Handle error based on error message } } ``` -------------------------------- ### Get All Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/api-reference.md Retrieve all available tip accounts from the Block Engine. The response contains a JSON Value with an array of tip account public keys. ```rust let tip_accounts_response = sdk.get_tip_accounts().await?; let tip_accounts = tip_accounts_response["result"].as_array().unwrap(); for tip_account in tip_accounts { println!("Tip Account: {}", tip_account.as_str().unwrap()); } ``` -------------------------------- ### Get Random Tip Account and Use in Transaction Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md This snippet shows how to retrieve a random tip account's public key using the SDK and then utilize this public key within a transaction. ```rust let tip_account = sdk.get_random_tip_account().await?; let tip_pubkey = Pubkey::from_str(&tip_account)?; // Use tip_pubkey in transaction ``` -------------------------------- ### Setting RUST_LOG Environment Variable Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Examples of exporting the RUST_LOG environment variable to control the logging output level for the tracing subscriber. The default level is 'info' if not set. ```bash export RUST_LOG=info ``` ```bash export RUST_LOG=debug ``` ```bash export RUST_LOG=trace ``` ```bash export RUST_LOG=off ``` -------------------------------- ### Initialize SDK with Local Endpoint Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Initialize the SDK to connect to a local or custom Jito-compatible endpoint. Ensure the local server is running and accessible. ```rust // Custom or local endpoint let sdk = JitoJsonRpcSDK::new("http://localhost:8080/api/v1", None); ``` -------------------------------- ### Initialize SDK with Production Mainnet Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Initialize the SDK for the Jito production mainnet. This configuration does not require a UUID. ```rust // Production mainnet (no UUID) let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", None); ``` -------------------------------- ### Send Transaction Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This is an example of a successful JSON-RPC response after sending a transaction. The result field contains the transaction signature. ```json { "jsonrpc": "2.0", "id": 1, "result": "5sKpMxUsKqbDvKJmJVahh9gM9eHSFZ9K3wazKKUJQVbX4Y9xnJxKKkMVfBF7NRV6" } ``` -------------------------------- ### Initialize SDK with Custom Endpoint Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Use this snippet to initialize the SDK with a custom JSON-RPC endpoint. Ensure the URL is valid and points to a Jito-compatible Block Engine. ```rust let sdk = JitoJsonRpcSDK::new("https://custom.endpoint.com/api/v1", None); ``` -------------------------------- ### Initialize Jito SDK with Default Endpoints Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Shows how to initialize the JitoJsonRpcSDK for development and production environments using recommended default endpoints. For production, a UUID is optionally provided. ```rust // Development let sdk = JitoJsonRpcSDK::new( "https://testnet.block-engine.jito.wtf/api/v1", None ); // Production let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", Some(uuid_from_config) ); ``` -------------------------------- ### Initialize SDK with Testnet Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Initialize the SDK for the Jito testnet. This configuration does not require a UUID. ```rust // Testnet without UUID let sdk = JitoJsonRpcSDK::new("https://testnet.block-engine.jito.wtf/api/v1", None); ``` -------------------------------- ### Get Inflight Bundle Statuses Endpoint Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Retrieve the in-flight status of bundles. ```APIDOC ## POST /getInflightBundleStatuses ### Description Get in-flight status of bundles. ### Method POST ### Endpoint /getInflightBundleStatuses ### Parameters #### Request Body (Schema defined in endpoints.md) ### Response (Schema defined in endpoints.md) ``` -------------------------------- ### Initialize Jito SDK with Logging Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Initializes the JitoJsonRpcSDK after setting up tracing for logging. This is useful for debugging and monitoring SDK operations. ```rust use tracing_subscriber::EnvFilter; fn init_tracing() { tracing_subscriber::fmt() .with_env_filter( EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info")) ) .init(); } #[tokio::main] async fn main() -> Result<(), Box> { init_tracing(); let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", None ); Ok(()) } ``` -------------------------------- ### Initialize JitoJsonRpcSDK Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Initializes the JitoJsonRpcSDK with a base URL. This is the first step to interact with the Jito RPC. ```rust use jito_rpc::JitoJsonRpcSDK; let base_url = "https://mainnet.jito.network/"; let sdk = JitoJsonRpcSDK::new(base_url); ``` -------------------------------- ### Get Bundle Statuses Endpoint Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Retrieve the confirmation status of submitted bundles. ```APIDOC ## POST /getBundleStatuses ### Description Get confirmation status of bundles. ### Method POST ### Endpoint /getBundleStatuses ### Parameters #### Request Body (Schema defined in endpoints.md) ### Response (Schema defined in endpoints.md) ``` -------------------------------- ### Initialize JitoJsonRpcSDK with Logging Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Initializes the JitoJsonRpcSDK with a base URL and enables logging. Logging is useful for debugging and understanding SDK behavior. ```rust use jito_rpc::JitoJsonRpcSDK; use tracing::info; let base_url = "https://mainnet.jito.network/"; let sdk = JitoJsonRpcSDK::new(base_url).with_logging(); info!("SDK initialized with logging."); ``` -------------------------------- ### Fetch and Print All Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Fetches all available tip accounts from the SDK and iterates through the results to print each account. ```rust let tip_accounts_response = sdk.get_tip_accounts().await?; if let Some(result) = tip_accounts_response.get("result") { if let Some(accounts) = result.as_array() { for account in accounts { println!("Tip Account: {}", account); } } } ``` -------------------------------- ### sendBundle Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This JSON object shows a successful response from the sendBundle method, containing the unique bundle UUID. ```json { "jsonrpc": "2.0", "id": 1, "result": "f47ac10b-58cc-4372-a567-0e02b2c3d479" } ``` -------------------------------- ### Setting Wallet Path Environment Variable Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Shows how to set the WALLET_PATH environment variable to specify the location of the Solana keypair file. This can be done globally or inline with a command. ```bash # Set wallet path export WALLET_PATH=~/.config/solana/id.json # Or inline with command WALLET_PATH=./keypair.json cargo run --example basic_txn ``` -------------------------------- ### Construct JitoJsonRpcSDK Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/types.md Shows how to initialize the JitoJsonRpcSDK client. You can create an instance with just a base URL or with an additional UUID for rate-limited access. ```rust let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", None); let sdk_with_uuid = JitoJsonRpcSDK::new(url, Some("uuid-string".to_string())); ``` -------------------------------- ### getInflightBundleStatuses Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/endpoints.md This JSON object shows a typical response when querying the in-flight status of bundles, including bundle ID and its current status. ```json { "jsonrpc": "2.0", "id": 1, "result": { "value": [ { "bundle_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "status": "Landed" } ] } } ``` -------------------------------- ### Jito Rust RPC SDK Configuration with Rate-Limit Approval UUID Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Initialize the SDK with a connection URL and a JITO_UUID for rate-limit approval. Ensure the JITO_UUID environment variable is set. ```rust let uuid = std::env::var("JITO_UUID")?; let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", Some(uuid)); ``` -------------------------------- ### Initialize SDK with UUID for Rate Limiting Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Initialize the SDK with a UUID for approved rate-limited access. Ensure the provided UUID is valid. ```rust // With UUID for rate limiting let uuid = "550e8400-e29b-41d4-a716-446655440000".to_string(); let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", Some(uuid)); ``` -------------------------------- ### Get Random Tip Account Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Retrieves a single random tip account. This is useful when you need to select a tip account without a specific preference. ```rust use jito_rpc::JitoJsonRpcSDK; let base_url = "https://mainnet.jito.network/"; let sdk = JitoJsonRpcSDK::new(base_url); let random_tip_account = sdk.get_random_tip_account().await.expect("Failed to get random tip account"); println!("Random Tip Account: {:?}", random_tip_account); ``` -------------------------------- ### Default HTTP Client Initialization Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md The SDK internally creates a new reqwest::Client with default settings during initialization. ```rust // Created internally in SDK::new() let client = Client::new(); ``` -------------------------------- ### Get In-Flight Bundle Statuses Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/api-reference.md Retrieves the status of in-flight bundles. Use this when you need to check the on-chain confirmation status of bundles that have been submitted but not yet finalized. ```rust pub async fn get_in_flight_bundle_statuses(&self, bundle_uuids: Vec) -> Result ``` ```json { "jsonrpc": "2.0", "result": { "value": [ { "bundle_id": "uuid", "status": "Pending|Landed|Invalid|Failed" } ] }, "id": 1 } ``` ```rust let inflight_response = sdk.get_in_flight_bundle_statuses(vec![bundle_uuid.to_string()]).await?; if let Some(result) = inflight_response.get("result") { if let Some(value) = result.get("value") { if let Some(statuses) = value.as_array() { if let Some(status) = statuses.first() { match status["status"].as_str() { Some("Landed") => println!("Bundle has landed!"), Some("Pending") => println!("Still pending..."), Some("Failed") => println!("Bundle failed!"), _ => println!("Unknown status"), } } } } } ``` -------------------------------- ### Pretty Print Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Fetches tip accounts and then formats them for display using the `prettify` utility. This enhances readability of the output. ```rust use jito_rpc::JitoJsonRpcSDK; let base_url = "https://mainnet.jito.network/"; let sdk = JitoJsonRpcSDK::new(base_url); let tip_accounts = sdk.get_tip_accounts().await.expect("Failed to get tip accounts"); let pretty_accounts = sdk.prettify(tip_accounts); println!("Pretty Tip Accounts: {}", pretty_accounts); ``` -------------------------------- ### Connection Reuse for Performance Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Demonstrates the importance of reusing the SDK instance to leverage internal connection pooling. Creating a new SDK instance for each call leads to inefficient client creation. ```rust // Good: Reuse same SDK instance let sdk = JitoJsonRpcSDK::new(url, uuid); for i in 0..100 { let _ = sdk.get_tip_accounts().await; // Reuses connections } // Avoid: Creating new SDK each time (new client each time) for i in 0..100 { let sdk = JitoJsonRpcSDK::new(url, uuid.clone()); // Creates new client let _ = sdk.get_tip_accounts().await; } ``` -------------------------------- ### JitoJsonRpcSDK::new() Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Initializes a new JitoJsonRpcSDK client. Supports configuration via base URL and UUID. ```APIDOC ## JitoJsonRpcSDK::new() ### Description Initializes a new instance of the Jito JSON RPC SDK client. This constructor allows for setting up the client with a base URL and a UUID for authentication and rate limiting. ### Method `JitoJsonRpcSDK::new(base_url: &str, uuid: &str)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let client = JitoJsonRpcSDK::new("https://mainnet.rpc.jito.network", "your-uuid"); ``` ### Response #### Success Response An initialized `JitoJsonRpcSDK` client instance. #### Response Example ```rust // No direct response example, but successful initialization returns a client object. ``` ``` -------------------------------- ### Send Bundle and Handle Errors Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Demonstrates how to send a bundle using the SDK and handle potential errors, distinguishing between logical and network errors. ```rust match sdk.send_bundle(params, None).await { Ok(response) => { /* process response */ }, Err(e) => eprintln!("Error: {}", e), } ``` -------------------------------- ### Rate Limiting Response Example Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/errors.md This JSON structure represents a rate limiting error response from the Jito RPC, indicated by an HTTP 429 status code. It suggests implementing backoff strategies or batching requests. ```json { "jsonrpc": "2.0", "error": { "code": -32005, "message": "Too many requests" } } ``` -------------------------------- ### Initialize JitoJsonRpcSDK with UUID Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Initializes the JitoJsonRpcSDK with a base URL and a UUID for rate limiting. Using a UUID can provide different rate limits. ```rust use jito_rpc::JitoJsonRpcSDK; let base_url = "https://mainnet.jito.network/"; let uuid = "your-uuid-here"; let sdk = JitoJsonRpcSDK::new(base_url).with_uuid(uuid); ``` -------------------------------- ### Environment-Based Jito Rust RPC SDK Configuration Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Configure the SDK using environment variables for both the connection URL and the JITO_UUID. Provides flexibility in setting up the connection. ```rust let url = std::env::var("BLOCK_ENGINE_URL") .unwrap_or_else(|_| "https://mainnet.block-engine.jito.wtf/api/v1".to_string()); let uuid = std::env::var("JITO_UUID").ok(); let sdk = JitoJsonRpcSDK::new(&url, uuid); ``` -------------------------------- ### Thread-Safe SDK Usage with Arc Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md The `JitoJsonRpcSDK` is `Send` and `Sync`, allowing it to be safely shared across threads using `Arc`. This example demonstrates cloning an `Arc`-wrapped SDK instance for use in a spawned Tokio task. ```rust let sdk = Arc::new(JitoJsonRpcSDK::new(url, None)); let sdk_clone = sdk.clone(); tokio::spawn(async move { let _ = sdk_clone.get_tip_accounts().await; }); ``` -------------------------------- ### Shared Jito SDK Instance for Concurrency Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Demonstrates how to create a shared Jito SDK instance using Arc for concurrent use across multiple tasks. This is efficient for applications making multiple RPC calls simultaneously. ```rust use std::sync::Arc; #[tokio::main] async fn main() -> Result<()> { let sdk = Arc::new(JitoJsonRpcSDK::new(url, None)); // Clone for concurrent use let sdk1 = sdk.clone(); let sdk2 = sdk.clone(); let handle1 = tokio::spawn(async move { sdk1.get_tip_accounts().await }); let handle2 = tokio::spawn(async move { sdk2.send_bundle(params, None).await }); let (result1, result2) = tokio::join!(handle1, handle2); Ok(()) } ``` -------------------------------- ### Fetch All Tip Accounts Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Fetches all available tip accounts from the Jito network. This method is useful for understanding where tips can be sent. ```rust use jito_rpc::JitoJsonRpcSDK; let base_url = "https://mainnet.jito.network/"; let sdk = JitoJsonRpcSDK::new(base_url); let tip_accounts = sdk.get_tip_accounts().await.expect("Failed to get tip accounts"); println!("Tip Accounts: {:?}", tip_accounts); ``` -------------------------------- ### Validate send_bundle Parameters in Rust Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/errors.md Illustrates valid and invalid parameter formats for the `send_bundle` method, including transaction arrays, encoding options, empty arrays, and excessive transaction counts. Ensure your parameters conform to these examples before sending. ```rust // Valid: Array of transactions let params = json!([serialized_tx1, serialized_tx2]); ``` ```rust // Valid: Full params with encoding let params = json!([ [serialized_tx1, serialized_tx2], {"encoding": "base64"} ]); ``` ```rust // Invalid: Empty array let params = json!([]); // Error: "at least one transaction" ``` ```rust // Invalid: More than 5 transactions let params = json!([tx1, tx2, tx3, tx4, tx5, tx6]); // Error: "at most 5" ``` ```rust // Invalid: Not an array let params = json!({"transactions": [tx1]}); // Error: "expected an array" ``` -------------------------------- ### JitoJsonRpcSDK Constructor Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Initializes the JitoJsonRpcSDK with a base URL and an optional UUID for rate limiting. ```APIDOC ## JitoJsonRpcSDK Constructor ### Description Initializes the JitoJsonRpcSDK with a base URL and an optional UUID for rate limiting. ### Method `new(base_url, uuid)` ### Parameters - **base_url** (string) - Required - The base URL for the Jito RPC endpoint. - **uuid** (string) - Optional - A unique identifier for rate limiting purposes. ``` -------------------------------- ### Create JitoJsonRpcSDK Client Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/api-reference.md Instantiate the JitoJsonRpcSDK client. Use a UUID for rate-limit approved access. Requires the base URL of the Block Engine API. ```rust use jito_sdk_rust::JitoJsonRpcSDK; // Without UUID let sdk = JitoJsonRpcSDK::new("https://mainnet.block-engine.jito.wtf/api/v1", None); // With UUID for rate-limit approved access let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", Some("your-uuid-here".to_string()) ); ``` -------------------------------- ### SDK Source Code Modification for Custom Client Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Illustrates how to modify the SDK's source code to accept and use a custom reqwest::Client, enabling advanced configuration like custom timeouts or proxies. ```rust // Option 2: Modify SDK source code to use custom client: // Change: let client = Client::new(); // To: pub fn with_client(base_url: &str, uuid: Option, client: Client) -> Self ``` -------------------------------- ### UUID Usage in Jito SDK Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Demonstrates how to initialize the JitoJsonRpcSDK with and without a UUID for rate-limited access. Use `None` for development and a UUID for production. ```rust // Development: No UUID required let sdk = JitoJsonRpcSDK::new(url, None); ``` ```rust // Production: Use UUID from environment or config let uuid = std::env::var("JITO_UUID").ok(); let sdk = JitoJsonRpcSDK::new(url, uuid); ``` ```rust // Dynamic UUID assignment fn create_sdk_with_config(config: &Config) -> JitoJsonRpcSDK { JitoJsonRpcSDK::new( &config.block_engine_url, config.jito_uuid.clone() ) } ``` -------------------------------- ### Initialize Jito SDK with UUID Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Initializes the JitoJsonRpcSDK using a UUID from the environment variable JITO_UUID. This is required for rate-limited access. ```rust let uuid = std::env::var("JITO_UUID") .expect("Set JITO_UUID environment variable"); let sdk = JitoJsonRpcSDK::new( "https://mainnet.block-engine.jito.wtf/api/v1", Some(uuid) ); ``` -------------------------------- ### Custom Logging with Tracing Macros Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/configuration.md Demonstrates how to use tracing macros (info!, error!) within your application to log events related to SDK operations, such as bundle submission results or failures. ```rust use tracing::{info, debug, warn, error}; match sdk.send_bundle(params, None).await { Ok(response) => info!("Bundle submitted: {:?}", response), Err(e) => error!("Bundle failed: {}", e), } ``` -------------------------------- ### Struct-Based Jito Configuration Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/usage-examples.md Configure the Jito SDK using a struct that reads from environment variables. This is useful for setting up the RPC client with base URL and optional UUID. ```rust use std::sync::Arc; #[derive(Clone)] struct JitoConfig { base_url: String, uuid: Option, } impl JitoConfig { fn from_env() -> Self { JitoConfig { base_url: std::env::var("JITO_URL") .unwrap_or_else(|_| "https://mainnet.block-engine.jito.wtf/api/v1".to_string() ), uuid: std::env::var("JITO_UUID").ok(), } } fn create_sdk(&self) -> JitoJsonRpcSDK { JitoJsonRpcSDK::new(&self.base_url, self.uuid.clone()) } } #[tokio::main] async fn main() -> Result<()> { let config = JitoConfig::from_env(); let sdk = config.create_sdk(); // Use SDK let accounts = sdk.get_tip_accounts().await?; println!("{:?}", accounts); Ok(()) } ``` -------------------------------- ### Utility Methods Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Utility methods for formatting and display. ```APIDOC ## Utility Methods ### Description Utility methods for formatting and display. ### `prettify(value)` #### Description Formats a JSON value for display. #### Parameters - **value** (JsonValue) - Required - The JSON value to format. #### Returns - `string` - The formatted JSON string. ``` -------------------------------- ### Bundle Methods Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/MANIFEST.md Methods for submitting and tracking bundles. ```APIDOC ## Bundle Methods ### Description Methods for submitting and tracking bundles. ### `send_bundle(params, uuid)` #### Description Submits a bundle to the Jito network. #### Parameters - **params** (BundleParams) - Required - The parameters for the bundle submission. - **uuid** (string) - Optional - A unique identifier for the submission. #### Returns - `BundleSubmissionResult` - The result of the bundle submission. ### `get_bundle_statuses(bundle_uuids)` #### Description Checks the confirmation status of one or more bundles. #### Parameters - **bundle_uuids** (Vec) - Required - A list of bundle UUIDs to check. #### Returns - `Vec` - The confirmation statuses of the bundles. ### `get_in_flight_bundle_statuses(bundle_uuids)` #### Description Checks the in-flight status of one or more bundles. #### Parameters - **bundle_uuids** (Vec) - Required - A list of bundle UUIDs to check. #### Returns - `Vec` - The in-flight statuses of the bundles. ``` -------------------------------- ### Bundles Endpoint Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Submit bundles to the Jito network or retrieve tip accounts. ```APIDOC ## POST /bundles ### Description Submit bundles to the Jito network or retrieve tip accounts. ### Method POST ### Endpoint /bundles ### Parameters #### Request Body (Schema defined in endpoints.md) ### Response (Schema defined in endpoints.md) ``` -------------------------------- ### Submit and Track a Bundle Source: https://github.com/jito-labs/jito-rust-rpc/blob/master/_autodocs/README.md Demonstrates the process of submitting a bundle to the Jito network and subsequently tracking its status using its unique identifier. The `send_bundle` method returns a UUID, which is then used with `get_in_flight_bundle_statuses`. ```rust // Submit let response = sdk.send_bundle(Some(params), None).await?; let uuid = response["result"].as_str().unwrap(); // Track let status = sdk.get_in_flight_bundle_statuses(vec![uuid.to_string()]).await?; ```