[−][src]Struct ethers_providers::Provider
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]
&'_ self,
block_hash_or_number: impl Into<BlockId>
) -> Result<Block<TxHash>, ProviderError>
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]
&'_ self,
block_hash_or_number: impl Into<BlockId>
) -> Result<Block<Transaction>, ProviderError>
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]
&'_ self,
transaction_hash: T
) -> Result<Transaction, ProviderError>
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]
&'_ self,
transaction_hash: T
) -> Result<TransactionReceipt, ProviderError>
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]
&'_ self,
from: impl Into<NameOrAddress>,
block: Option<BlockNumber>
) -> Result<U256, ProviderError>
Returns the nonce of the address
pub async fn get_balance<'_>(
&'_ self,
from: impl Into<NameOrAddress>,
block: Option<BlockNumber>
) -> Result<U256, ProviderError>
[src]
&'_ self,
from: impl Into<NameOrAddress>,
block: Option<BlockNumber>
) -> Result<U256, ProviderError>
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]
&'_ self,
tx: &'_ TransactionRequest,
block: Option<BlockNumber>
) -> Result<Bytes, ProviderError>
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]
&'_ self,
tx: &'_ TransactionRequest
) -> Result<U256, ProviderError>
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]
&'_ self,
__arg1: TransactionRequest
) -> Result<PendingTransaction<'_, P>, ProviderError>
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]
&'_ self,
tx: &'_ Transaction
) -> Result<PendingTransaction<'_, P>, ProviderError>
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]
&'_ self,
data: T,
from: &'_ Address
) -> Result<Signature, ProviderError>
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]
&'_ self,
filter: &'_ Filter
) -> Result<Vec<Log>, ProviderError>
Returns an array (possibly empty) of logs that match the filter
pub async fn watch<'_, '_, '_>(
&'_ self,
filter: &'_ Filter
) -> Result<impl FilterStream<Log> + '_, ProviderError>
[src]
&'_ self,
filter: &'_ Filter
) -> Result<impl FilterStream<Log> + '_, ProviderError>
Streams matching filter logs
pub async fn watch_blocks<'_, '_>(
&'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
[src]
&'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
Streams new block hashes
pub async fn watch_pending_transactions<'_, '_>(
&'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
[src]
&'_ self
) -> Result<impl FilterStream<H256> + '_, ProviderError>
Streams pending transactions
pub async fn new_filter<'_, '_>(
&'_ self,
filter: FilterKind<'_>
) -> Result<U256, ProviderError>
[src]
&'_ self,
filter: FilterKind<'_>
) -> Result<U256, ProviderError>
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]
&'_ self,
id: T
) -> Result<bool, ProviderError>
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]
&'_ self,
id: T
) -> Result<Vec<R>, ProviderError> where
T: Into<U256>,
R: for<'a> Deserialize<'a>,
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 hasheseth_newPendingTransactionFilter
:H256
, returns transaction hasheseth_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]
&'_ self,
at: impl Into<NameOrAddress>,
block: Option<BlockNumber>
) -> Result<Bytes, ProviderError>
Returns the deployed code at a given address
pub async fn resolve_name<'_, '_>(
&'_ self,
ens_name: &'_ str
) -> Result<Address, ProviderError>
[src]
&'_ self,
ens_name: &'_ str
) -> Result<Address, ProviderError>
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]
&'_ self,
address: Address
) -> Result<String, ProviderError>
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]
Auto Trait Implementations
impl<P> RefUnwindSafe for Provider<P> where
P: RefUnwindSafe,
P: RefUnwindSafe,
impl<P> Send for Provider<P> where
P: Send,
P: Send,
impl<P> Sync for Provider<P> where
P: Sync,
P: Sync,
impl<P> Unpin for Provider<P> where
P: Unpin,
P: Unpin,
impl<P> UnwindSafe for Provider<P> where
P: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,