pub trait ProviderExt: Sealed {
    type Error: Debug;

    // Required methods
    fn try_connect<'life0, 'async_trait>(
        url: &'life0 str
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait,
             'life0: 'async_trait;
    fn set_chain(&mut self, chain: impl Into<Chain>) -> &mut Self;

    // Provided methods
    fn connect<'life0, 'async_trait>(
        url: &'life0 str
    ) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
       where Self: Sized + Send + 'async_trait,
             'life0: '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.llamarpc.com").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.llamarpc.com").unwrap().set_chain(Chain::Mainnet);

Required Associated Types§

source

type Error: Debug

The error type that can occur when creating a provider

Required Methods§

source

fn try_connect<'life0, 'async_trait>( url: &'life0 str ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, 'life0: 'async_trait,

Try to create a new Provider

source

fn set_chain(&mut self, chain: impl Into<Chain>) -> &mut Self

Customized Provider settings for chain

Provided Methods§

source

fn connect<'life0, 'async_trait>( url: &'life0 str ) -> Pin<Box<dyn Future<Output = Self> + Send + 'async_trait>>
where Self: Sized + Send + 'async_trait, 'life0: 'async_trait,

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

source

fn for_chain(self, chain: impl Into<Chain>) -> Self
where Self: Sized,

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

Object Safety§

This trait is not object safe.

Implementors§