| Crates.io | gas-network-sdk |
| lib.rs | gas-network-sdk |
| version | 0.1.0 |
| created_at | 2025-08-28 09:39:31.351213+00 |
| updated_at | 2025-08-28 09:39:31.351213+00 |
| description | Rust SDK for Gas Network API - gas price prediction and optimization |
| homepage | |
| repository | https://github.com/rshuwy/gas-network-sdk |
| max_upload_size | |
| id | 1813849 |
| size | 66,685 |
A Rust SDK for the Gas Network API, providing gas price prediction and optimization for blockchain transactions.
Add this to your Cargo.toml:
[dependencies]
gas-network-sdk = "0.1.0"
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(())
}
let client = GasNetworkClient::new("your_api_key".to_string())?;
// 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?;
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);
}
}
}
let distribution = client.get_gas_distribution(Chain::Ethereum).await?;
// Get oracle data for a specific chain ID
let oracle_data = client.get_oracle_data(1).await?; // Ethereum mainnet
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),
}
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.
Licensed under either of
at your option.