[][src]Struct ethers_providers::Provider

pub struct Provider<P>(_, _);

An abstract provider for interacting with the Ethereum JSON RPC API. Must be instantiated with a data transport which implements the JsonRpcClient trait (e.g. HTTP, Websockets etc.)

Example

use ethers::providers::{JsonRpcClient, Provider, Http};
use std::convert::TryFrom;

let provider = Provider::<Http>::try_from(
    "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"
).expect("could not instantiate HTTP Provider");

let block = provider.get_block(100u64).await?;
println!("Got block: {}", serde_json::to_string(&block)?);

Implementations

impl<P: JsonRpcClient> Provider<P>[src]

pub fn new(provider: P) -> Self[src]

Instantiate a new provider with a backend.

pub async fn get_block_number<'_>(&'_ self) -> Result<U64, ProviderError>[src]

Gets the latest block number via the eth_BlockNumber API

pub async fn get_block<'_>(
    &'_ self,
    block_hash_or_number: impl Into<BlockId>
) -> Result<Block<TxHash>, ProviderError>
[src]

Gets the block at block_hash_or_number (transaction hashes only)

pub async fn get_block_with_txs<'_>(
    &'_ self,
    block_hash_or_number: impl Into<BlockId>
) -> Result<Block<Transaction>, ProviderError>
[src]

Gets the block at block_hash_or_number (full transactions included)

pub async fn get_transaction<'_, T: Send + Sync + Into<TxHash>>(
    &'_ self,
    transaction_hash: T
) -> Result<Transaction, ProviderError>
[src]

Gets the transaction with transaction_hash

pub async fn get_transaction_receipt<'_, T: Send + Sync + Into<TxHash>>(
    &'_ self,
    transaction_hash: T
) -> Result<TransactionReceipt, ProviderError>
[src]

Gets the transaction receipt with transaction_hash

pub async fn get_gas_price<'_>(&'_ self) -> Result<U256, ProviderError>[src]

Gets the current gas price as estimated by the node

pub async fn get_accounts<'_>(&'_ self) -> Result<Vec<Address>, ProviderError>[src]

Gets the accounts on the node

pub async fn get_transaction_count<'_>(
    &'_ self,
    from: impl Into<NameOrAddress>,
    block: Option<BlockNumber>
) -> Result<U256, ProviderError>
[src]

Returns the nonce of the address

pub async fn get_balance<'_>(
    &'_ self,
    from: impl Into<NameOrAddress>,
    block: Option<BlockNumber>
) -> Result<U256, ProviderError>
[src]

Returns the account's balance

pub async fn get_chainid<'_>(&'_ self) -> Result<U256, ProviderError>[src]

Returns the currently configured chain id, a value used in replay-protected transaction signing as introduced by EIP-155.

pub async fn call<'_, '_>(
    &'_ self,
    tx: &'_ TransactionRequest,
    block: Option<BlockNumber>
) -> Result<Bytes, ProviderError>
[src]

Sends the read-only (constant) transaction to a single Ethereum node and return the result (as bytes) of executing it. This is free, since it does not change any state on the blockchain.

pub async fn estimate_gas<'_, '_>(
    &'_ self,
    tx: &'_ TransactionRequest
) -> Result<U256, ProviderError>
[src]

Sends a transaction to a single Ethereum node and return the estimated amount of gas required (as a U256) to send it This is free, but only an estimate. Providing too little gas will result in a transaction being rejected (while still consuming all provided gas).

pub async fn send_transaction<'_, '_>(
    &'_ self,
    __arg1: TransactionRequest
) -> Result<PendingTransaction<'_, P>, ProviderError>
[src]

Sends the transaction to the entire Ethereum network and returns the transaction's hash This will consume gas from the account that signed the transaction.

pub async fn send_raw_transaction<'_, '_, '_>(
    &'_ self,
    tx: &'_ Transaction
) -> Result<PendingTransaction<'_, P>, ProviderError>
[src]

Send the raw RLP encoded transaction to the entire Ethereum network and returns the transaction's hash This will consume gas from the account that signed the transaction.

pub async fn sign<'_, '_, T: Into<Bytes>>(
    &'_ self,
    data: T,
    from: &'_ Address
) -> Result<Signature, ProviderError>
[src]

Signs data using a specific account. This account needs to be unlocked.

pub async fn get_logs<'_, '_>(
    &'_ self,
    filter: &'_ Filter
) -> Result<Vec<Log>, ProviderError>
[src]

Returns an array (possibly empty) of logs that match the filter

pub async fn watch<'_, '_, '_>(
    &'_ self,
    filter: &'_ Filter
) -> Result<impl FilterStream<Log> + '_, ProviderError>
[src]

Streams matching filter logs

pub async fn watch_blocks<'_, '_>(
    &'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
[src]

Streams new block hashes

pub async fn watch_pending_transactions<'_, '_>(
    &'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
[src]

Streams pending transactions

pub async fn new_filter<'_, '_>(
    &'_ self,
    filter: FilterKind<'_>
) -> Result<U256, ProviderError>
[src]

Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call get_filter_changes with the filter id.

pub async fn uninstall_filter<'_, T: Into<U256>>(
    &'_ self,
    id: T
) -> Result<bool, ProviderError>
[src]

Uninstalls a filter

pub async fn get_filter_changes<'_, T, R>(
    &'_ self,
    id: T
) -> Result<Vec<R>, ProviderError> where
    T: Into<U256>,
    R: for<'a> Deserialize<'a>, 
[src]

Polling method for a filter, which returns an array of logs which occurred since last poll.

This method must be called with one of the following return types, depending on the filter type:

  • eth_newBlockFilter: H256, returns block hashes
  • eth_newPendingTransactionFilter: H256, returns transaction hashes
  • eth_newFilter: Log, returns raw logs

If one of these types is not used, decoding will fail and the method will return an error.

pub async fn get_code<'_>(
    &'_ self,
    at: impl Into<NameOrAddress>,
    block: Option<BlockNumber>
) -> Result<Bytes, ProviderError>
[src]

Returns the deployed code at a given address

pub async fn resolve_name<'_, '_>(
    &'_ self,
    ens_name: &'_ str
) -> Result<Address, ProviderError>
[src]

Returns the address that the ens_name resolves to (or None if not configured).

Panics

If the bytes returned from the ENS registrar/resolver cannot be interpreted as an address. This should theoretically never happen.

pub async fn lookup_address<'_>(
    &'_ self,
    address: Address
) -> Result<String, ProviderError>
[src]

Returns the ENS name the address resolves to (or None if not configured).

Panics

If the bytes returned from the ENS registrar/resolver cannot be interpreted as a string. This should theoretically never happen.

pub fn ens<T: Into<Address>>(self, ens: T) -> Self[src]

Sets the ENS Address (default: mainnet)

Trait Implementations

impl<P: Clone> Clone for Provider<P>[src]

impl<P: Debug> Debug for Provider<P>[src]

impl<'_> TryFrom<&'_ str> for Provider<HttpProvider>[src]

type Error = ParseError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<P> RefUnwindSafe for Provider<P> where
    P: RefUnwindSafe

impl<P> Send for Provider<P> where
    P: Send

impl<P> Sync for Provider<P> where
    P: Sync

impl<P> Unpin for Provider<P> where
    P: Unpin

impl<P> UnwindSafe for Provider<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,