Trait ethers_providers::ProviderExt
source · pub trait ProviderExt: Sealed {
type Error: Debug;
fn try_connect<'life0, 'async_trait>(
url: &'life0 str
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where
Self: Sized,
'life0: 'async_trait,
Self: 'async_trait;
fn set_chain(&mut self, chain: impl Into<Chain>) -> &mut Self;
fn connect<'life0, 'async_trait>(
url: &'life0 str
) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where
Self: Sized,
'life0: 'async_trait,
Self: Send + 'async_trait,
{ ... }
fn for_chain(self, chain: impl Into<Chain>) -> Self
where
Self: Sized,
{ ... }
}
Expand description
Extension trait for Provider
Note: this is currently sealed until https://github.com/gakonst/ethers-rs/pull/1267 is finalized
Example
Automatically configure poll interval via eth_getChainId
Note that this will send an RPC to retrieve the chain id.
let http_provider = Provider::<Http>::connect("https://eth-mainnet.alchemyapi.io/v2/API_KEY").await;
This is essentially short for
use std::convert::TryFrom;
use ethers_core::types::Chain;
use ethers_providers::{Http, Provider, ProviderExt};
let http_provider = Provider::<Http>::try_from("https://eth-mainnet.alchemyapi.io/v2/API_KEY").unwrap().set_chain(Chain::Mainnet);