Struct ethers_providers::Provider[][src]

pub struct Provider<P> { /* fields omitted */ }
Expand description

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::{Middleware, 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

Instantiate a new provider with a backend.

Sets the ENS Address (default: mainnet)

Sets the default polling interval for event filters and pending transactions (default: 7 seconds)

Gets the polling interval which the provider currently uses for event filters and pending transactions (default: 7 seconds)

Direct connection to a websocket endpoint

Direct connection to an IPC socket.

Provider that uses a quorum

Returns a Provider instantiated with an internal “mock” transport.

Example

use ethers_core::types::U64;
use ethers_providers::{Middleware, Provider};
// Instantiate the provider
let (provider, mock) = Provider::mocked();
// Push the mock response
mock.push(U64::from(12))?;
// Make the call
let blk = provider.get_block_number().await.unwrap();
// The response matches
assert_eq!(blk.as_u64(), 12);
// and the request as well!
mock.assert_request("eth_blockNumber", ()).unwrap();

Trait Implementations

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the current client version using the web3_clientVersion RPC.

Gets the latest block number via the eth_BlockNumber API

Gets the block at block_hash_or_number (transaction hashes only)

Gets the block at block_hash_or_number (full transactions included)

Gets the block uncle count at block_hash_or_number

Gets the block uncle at block_hash_or_number and idx

Gets the transaction with transaction_hash

Gets the transaction receipt with transaction_hash

Returns all receipts for a block.

Note that this uses the eth_getBlockReceipts RPC, which is non-standard and currently supported by Erigon.

Gets the current gas price as estimated by the node

Gets a heuristic recommendation of max fee per gas and max priority fee per gas for EIP-1559 compatible transactions.

Gets the accounts on the node

Returns the nonce of the address

Returns the account’s balance

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

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.

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

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.

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.

The JSON-RPC provider is at the bottom-most position in the middleware stack. Here we check if it has the key for the sender address unlocked, as well as supports the eth_sign call.

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

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

Streams matching filter logs

Streams new block hashes

Streams pending transactions

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.

Uninstalls a filter

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.

Get the storage of an address for a particular slot location

Returns the deployed code at a given address

Returns the EIP-1186 proof response https://github.com/ethereum/EIPs/issues/1186

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.

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.

Returns the details of all transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. Ref: Here

Returns a summary of all the transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. Ref: Here

Returns the number of transactions currently pending for inclusion in the next block(s), as well as the ones that are being scheduled for future execution only. Ref: Here

Executes the given call and returns a number of possible traces for it

Traces a call to eth_sendRawTransaction without making the call, returning the traces

Replays a transaction, returning the traces

Replays all transactions in a block returning the requested traces for each transaction

Returns traces created at given block

Return traces matching the given filter

Returns trace at the given position

Returns all traces of a given transaction

Returns all receipts for that block. Must be done on a parity node.

The next middleware in the stack

The HTTP or Websocket provider.

Helper for filling a transaction

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca) Read more

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA) Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more