Trait ethers_middleware::gas_oracle::GasOracle
source · pub trait GasOracle: Send + Sync + Debug {
// Required methods
fn fetch<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<U256>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn estimate_eip1559_fees<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(U256, U256)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
An Ethereum gas price oracle.
Example
use ethers_core::types::U256;
use ethers_middleware::gas_oracle::{GasCategory, GasNow, GasOracle};
let oracle = GasNow::default().category(GasCategory::SafeLow);
let gas_price = oracle.fetch().await?;
assert!(gas_price > U256::zero());
Required Methods§
sourcefn fetch<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<U256>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn fetch<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<U256>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Makes an asynchronous HTTP query to the underlying GasOracle
to fetch the current gas
price estimate.
Example
use ethers_core::types::U256;
use ethers_middleware::gas_oracle::{GasCategory, GasNow, GasOracle};
let oracle = GasNow::default().category(GasCategory::SafeLow);
let gas_price = oracle.fetch().await?;
assert!(gas_price > U256::zero());
sourcefn estimate_eip1559_fees<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<(U256, U256)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn estimate_eip1559_fees<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<(U256, U256)>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Makes an asynchronous HTTP query to the underlying GasOracle
to fetch the current max
gas fee and priority gas fee estimates.
Example
use ethers_core::types::U256;
use ethers_middleware::gas_oracle::{GasCategory, GasNow, GasOracle};
let oracle = GasNow::default().category(GasCategory::SafeLow);
let (max_fee, priority_fee) = oracle.estimate_eip1559_fees().await?;
assert!(max_fee > U256::zero());
assert!(priority_fee > U256::zero());