Expand description
§ethers-providers
Clients for interacting with Ethereum nodes.
This crate provides asynchronous Ethereum JSON-RPC compliant clients.
For more information, please refer to the book.
Warning
This library is in the process of being deprecated. See #2667 for more information.
§Websockets
This crate supports for WebSockets via tokio-tungstenite
.
Please ensure that you have the ws
feature enabled if you wish to use WebSockets:
[dependencies]
ethers-providers = { version = "2.0", features = ["ws"] }
§Interprocess Communication (IPC)
This crate supports for Interprocess Communication via Unix sockets and Windows named pipes.
Please ensure that you have the ipc
feature enabled if you wish to use IPC:
[dependencies]
ethers-providers = { version = "2.0", features = ["ipc"] }
§Ethereum Name Service
The provider may also be used to resolve Ethereum Name Service (ENS) names
to addresses (and vice versa).
The default ENS address is 0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
and can be overriden with the ens
method on the provider.
§Examples
let provider = Provider::<Http>::try_from("https://eth.llamarpc.com")?;
let block = provider.get_block(100u64).await?;
println!("Got block: {}", serde_json::to_string(&block)?);
let addr = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359".parse::<Address>()?;
let code = provider.get_code(addr, None).await?;
println!("Got code: {}", serde_json::to_string(&code)?);
Using ENS:
let provider = Provider::<Http>::try_from("https://eth.llamarpc.com")?;
// Resolve ENS name to Address
let name = "vitalik.eth";
let address = provider.resolve_name(name).await?;
// Lookup ENS name given Address
let resolved_name = provider.lookup_address(address).await?;
assert_eq!(name, resolved_name);
/// Lookup ENS field
let url = "https://vitalik.ca".to_string();
let resolved_url = provider.resolve_field(name, "url").await?;
assert_eq!(url, resolved_url);
/// Lookup and resolve ENS avatar
let avatar = "https://ipfs.io/ipfs/QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif".to_string();
let resolved_avatar = provider.resolve_avatar(name).await?;
assert_eq!(avatar, resolved_avatar.to_string());
Re-exports§
pub use test_provider::GOERLI;
pub use test_provider::MAINNET;
pub use test_provider::ROPSTEN;
Deprecated pub use test_provider::SEPOLIA;
pub use crate::Middleware;
Modules§
- admin
- Types for the admin api
- call_
raw - Overrides for the
eth_call
rpc method - dev_rpc
dev-rpc
- A middleware supporting development-specific JSON RPC methods
- ens
- Ethereum Name Service support Adapted from https://github.com/hhatto/rust-ens/blob/master/src/lib.rs
- erc
- ERC related utilities. Only supporting NFTs for now.
- legacy_
ws legacy-ws
- archival websocket
- spoof
- Provides types and methods for constructing an
eth_call
state override set - test_
provider - Pre-instantiated Infura HTTP clients which rotate through multiple API keys to prevent rate limits
Structs§
- Caller
- Holds the inputs to the
eth_call
rpc method along with the rpc provider. This type is constructed byCallBuilder::new
. - DevRpc
Middleware dev-rpc
DevRpcMiddleware
- Escalating
Pending - An EscalatingPending is a pending transaction that increases its own gas price over time, by broadcasting successive versions with higher gas prices.
- Filter
Watcher - Streams data from an installed filter via
eth_getFilterChanges
- Http
- A low-level JSON-RPC Client over HTTP.
- Http
Rate Limit Retry Policy - Implements RetryPolicy that will retry requests that errored with status code 429 i.e. TOO_MANY_REQUESTS
- Ipc
ipc
and (Unix or Windows) - A JSON-RPC Client over Unix IPC.
- Json
RpcError - A JSON-RPC 2.0 error
- JwtAuth
- Contains the JWT secret and claims parameters.
- JwtKey
- Generates a bearer token from a JWT secret
- LogQuery
- A log query provides streaming access to historical logs via a paginated
request. For streaming access to future logs, use
Middleware::watch
orMiddleware::subscribe_logs
- Map
- An implementer of
RawCall
that maps a functionf
over the output of the inner future. - Mock
Provider - Mock transport used in test environments.
- Node
Info - This includes general information about a running node, spanning networking and protocol details.
- Peer
Info - Represents a short summary of information known about a connected peer.
- Pending
Transaction - A pending transaction is a transaction which has been submitted but is not yet mined.
await
’ing on a pending transaction will resolve to a transaction receipt once the transaction has enoughconfirmations
. The default number of confirmations is 1, but may be adjusted with theconfirmations
method. If the transaction does not have enough confirmations or is not mined, the future will stay in the pending state. - 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.) - Quorum
Provider - A provider that bundles multiple providers and only returns a value to the caller once the quorum has been reached.
- Retry
Client - RetryClient presents as a wrapper around JsonRpcClient that will retry requests based with an exponential backoff and filtering based on RetryPolicy.
- Retry
Client Builder - Builder for a
RetryClient
- RwClient
- A client containing two clients.
- Subscription
Stream - Streams data from an installed filter via
eth_subscribe
- Transaction
Stream - Drains a stream of transaction hashes and yields entire
Transaction
. - Weighted
Provider - The configuration of a provider for the
QuorumProvider
- Ws
legacy-ws
- A JSON-RPC Client over Websockets.
Enums§
- Authorization
- Basic or bearer authentication in http or websocket transport
- Call
Builder - A builder which implements
RawCall
methods for overridingeth_call
parameters. - DevRpc
Middleware Error dev-rpc
- DevRpcMiddleware Errors
- Filter
Kind - Types of filters supported by the JSON-RPC.
- Http
Client Error - Error thrown when sending an HTTP request
- IpcError
ipc
and (Unix or Windows) - Error thrown when sending or receiving an IPC message.
- LogQuery
Error - Errors while querying for logs
- Mock
Error - Errors for the
MockProvider
- Mock
Response - Helper response type for
MockProvider
, allowing custom JSON-RPC errors to be provided.Value
for successful responses,Error
for JSON-RPC errors. - Node
Client - Node Clients
- Provider
Error - An error thrown when making a call to the provider
- Quorum
- Determines when the provider reached a quorum
- Quorum
Error - Error thrown when sending an HTTP request
- Retry
Client Error - Error thrown when:
- RwClient
Error - Error thrown when using either read or write client
- WsClient
Error legacy-ws
- Error thrown when sending a WS message
Constants§
- ADDR_
SELECTOR - addr(bytes32)
- DEFAULT_
LOCAL_ POLL_ INTERVAL - The polling interval to use for local endpoints, See
crate::is_local_endpoint()
- DEFAULT_
POLL_ INTERVAL - The default polling interval for filters and pending transactions
- ENS_
ADDRESS - ENS registry address (
0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
) - FIELD_
SELECTOR - text(bytes32, string)
- INTERFACE_
SELECTOR - supportsInterface(bytes4 interfaceID)
- NAME_
SELECTOR - name(bytes32)
Traits§
- Celo
Middleware celo
- Celo-specific extension trait
- Json
RpcClient - Trait which must be implemented by data transports to be used with the Ethereum JSON-RPC provider.
- Json
RpcClient Wrapper - Wrapper trait for
crate::JsonRpcClient
that erases generics and is object-safe. This trait is not intended for outside implementation - Middleware
- A middleware allows customizing requests send and received from an ethereum node.
- Middleware
Error MiddlewareError
is a companion trait tocrate::Middleware
. It describes error behavior that is common to all Middleware errors.- Provider
Ext - Extension trait for
Provider
- Pubsub
Client - A transport implementation supporting pub sub subscriptions.
- RawCall
- Provides methods for overriding parameters to the
eth_call
rpc method - Retry
Policy - RetryPolicy defines logic for which JsonRpcClient::Error instances should the client retry the request and try to recover from.
- RpcError
- An
RpcError
is an abstraction over error types returned by acrate::JsonRpcClient
. - Stream
Ext - An extension trait for
Stream
s that provides a variety of convenient combinator functions.
Functions§
- bytes_
32ify - Returns a number in bytes form with padding to fit in 32 bytes.
- get_
resolver - Returns a transaction request for calling the
resolver
method on the ENS server - interval
- Create a stream that emits items at a fixed interval. Used for rate control
- is_
local_ endpoint - Returns true if the endpoint is local
- maybe
- Calls the future if
item
is None, otherwise returns afutures::ok
- namehash
- Returns the ENS namehash as specified in EIP-137
- parameterhash
- Returns the ENS record key hash EIP-634
- resolve
- Returns a transaction request for calling
- reverse_
address - Returns the reverse-registrar name of an address.
- supports_
interface - Returns a transaction request for checking interface support
Type Aliases§
- Escalation
Policy - A simple gas escalation policy