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);

Required Associated Types§

The error type that can occur when creating a provider

Required Methods§

Try to create a new Provider

Customized Provider settings for chain

Provided Methods§

Creates a new instance connected to the given url, exit on error

Customize Provider settings for chain.

E.g. Chain::average_blocktime_hint() returns the average block time which can be used to tune the polling interval.

Returns the customized Provider

Implementors§