gas-network-sdk

Crates.iogas-network-sdk
lib.rsgas-network-sdk
version0.1.0
created_at2025-08-28 09:39:31.351213+00
updated_at2025-08-28 09:39:31.351213+00
descriptionRust SDK for Gas Network API - gas price prediction and optimization
homepage
repositoryhttps://github.com/rshuwy/gas-network-sdk
max_upload_size
id1813849
size66,685
(rshuwy)

documentation

README

Gas Network SDK

A Rust SDK for the Gas Network API, providing gas price prediction and optimization for blockchain transactions.

Features

  • Multi-chain support: Ethereum, Polygon, Bitcoin, SEI, Optimism, Arbitrum, Base, Linea, Unichain
  • Real-time gas price estimates with confidence levels
  • Base fee and blob fee predictions (Ethereum only)
  • Gas price distribution analysis (Ethereum only)
  • Oracle integration for on-chain gas data
  • Async/await support with tokio
  • Comprehensive error handling

Installation

Add this to your Cargo.toml:

[dependencies]
gas-network-sdk = "0.1.0"

Quick Start

use gas_network_sdk::{GasNetworkClient, Chain};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client with your API key
    let client = GasNetworkClient::new("your_api_key".to_string())?;
    
    // Get gas prices for Ethereum
    let gas_prices = client.get_gas_prices(Chain::Ethereum).await?;
    println!("Current gas prices: {:?}", gas_prices);
    
    // Get next block estimate with 90% confidence
    let estimate = client.get_next_block_estimate(Chain::Ethereum, Some(90)).await?;
    println!("Next block estimate: {} gwei", estimate.price);
    
    Ok(())
}

API Reference

Client Creation

let client = GasNetworkClient::new("your_api_key".to_string())?;

Gas Price Estimation

// Get comprehensive gas price data
let prices = client.get_gas_prices(Chain::Base).await?;

// Get specific confidence level estimate
let estimate = client.get_next_block_estimate(Chain::Ethereum, Some(95)).await?;

Base Fee Prediction (Ethereum only)

let base_fees = client.get_base_fee_estimates(Chain::Ethereum).await?;
println!("Current base fee: {} gwei", base_fees.base_fee_per_gas);
println!("Blob base fee: {} gwei", base_fees.blob_base_fee_per_gas);

// Get estimates for next 5 blocks
for block_estimate in &base_fees.estimated_base_fees {
    // Each block contains estimates with different confidence levels
    for (pending_block, estimates) in &block_estimate.pending_block {
        for estimate in estimates {
            println!("{}: Base fee {} gwei ({}% confidence)", 
                pending_block, estimate.base_fee, estimate.confidence);
        }
    }
}

Gas Distribution Analysis (Ethereum only)

let distribution = client.get_gas_distribution(Chain::Ethereum).await?;

Oracle Data

// Get oracle data for a specific chain ID
let oracle_data = client.get_oracle_data(1).await?; // Ethereum mainnet

Supported Chains

  • Ethereum
  • Polygon
  • Bitcoin
  • SEI
  • Optimism
  • Arbitrum
  • Base
  • Linea
  • Unichain

Error Handling

The SDK uses a comprehensive error system:

use gas_network_sdk::{GasNetworkError, Result};

match client.get_gas_prices(Chain::Ethereum).await {
    Ok(prices) => println!("Success: {:?}", prices),
    Err(GasNetworkError::InvalidApiKey) => eprintln!("Invalid API key"),
    Err(GasNetworkError::UnsupportedChain(chain)) => eprintln!("Unsupported chain: {}", chain),
    Err(GasNetworkError::Api { message }) => eprintln!("API error: {}", message),
    Err(e) => eprintln!("Other error: {}", e),
}

Authentication

You can optionally use an API key from Blocknative for higher rate limits. The API works without authentication but with rate limitations. Pass your API key when creating the client, or use a placeholder if you don't have one.

License

Licensed under either of

  • Apache License, Version 2.0
  • MIT License

at your option.

Commit count: 1

cargo fmt