use gas_network_sdk::{GasNetworkClient, Chain, Result};
#[tokio::main]
async fn main() -> Result<()> {
let api_key = std::env::var("GAS_NETWORK_API_KEY")
.unwrap_or_else(|_| "your_api_key_here".to_string());
let client = GasNetworkClient::new(api_key)?;
println!("=== Multi-Chain Gas Price Comparison ===\n");
let chains_to_check = vec![
Chain::Ethereum,
Chain::Base,
Chain::Arbitrum,
Chain::Optimism,
Chain::Polygon,
];
for chain in chains_to_check {
println!("📊 {} Gas Prices:", chain.as_str().to_uppercase());
match client.get_gas_prices(chain.clone()).await {
Ok(prices) => {
println!(" Block: #{}", prices.current_block_number);
println!(" Network: {}", prices.network);
println!(" Unit: {}", prices.unit);
let estimated = prices.estimated_prices();
if let Some(estimate) = estimated.first() {
println!(" Recommended: {} {} ({}% confidence)",
estimate.price, prices.unit, estimate.confidence);
if let Some(max_fee) = estimate.max_fee_per_gas {
println!(" Max Fee: {} {}", max_fee, prices.unit);
}
if let Some(priority_fee) = estimate.max_priority_fee_per_gas {
println!(" Priority Fee: {} {}", priority_fee, prices.unit);
}
}
println!(" Time since last block: ~{} ms", prices.ms_since_last_block);
}
Err(e) => {
println!(" ❌ Error: {}", e);
}
}
println!(); }
println!("=== Chain Comparison Complete ===");
Ok(())
}