Crate ethers_providers
source ·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;
Deprecatedpub use test_provider::SEPOLIA;
pub use crate::Middleware;
Modules§
- Types for the admin api
- Overrides for the
eth_call
rpc method - dev_rpc
dev-rpc
A middleware supporting development-specific JSON RPC methods - Ethereum Name Service support Adapted from https://github.com/hhatto/rust-ens/blob/master/src/lib.rs
- ERC related utilities. Only supporting NFTs for now.
- legacy_ws
legacy-ws
archival websocket - Provides types and methods for constructing an
eth_call
state override set - Pre-instantiated Infura HTTP clients which rotate through multiple API keys to prevent rate limits
Structs§
- Holds the inputs to the
eth_call
rpc method along with the rpc provider. This type is constructed byCallBuilder::new
. - DevRpcMiddleware
dev-rpc
DevRpcMiddleware
- An EscalatingPending is a pending transaction that increases its own gas price over time, by broadcasting successive versions with higher gas prices.
- Streams data from an installed filter via
eth_getFilterChanges
- A low-level JSON-RPC Client over HTTP.
- 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. - A JSON-RPC 2.0 error
- Contains the JWT secret and claims parameters.
- Generates a bearer token from a JWT secret
- 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
- An implementer of
RawCall
that maps a functionf
over the output of the inner future. - Mock transport used in test environments.
- This includes general information about a running node, spanning networking and protocol details.
- Represents a short summary of information known about a connected peer.
- 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. - 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.) - A provider that bundles multiple providers and only returns a value to the caller once the quorum has been reached.
- RetryClient presents as a wrapper around JsonRpcClient that will retry requests based with an exponential backoff and filtering based on RetryPolicy.
- Builder for a
RetryClient
- A client containing two clients.
- Streams data from an installed filter via
eth_subscribe
- Drains a stream of transaction hashes and yields entire
Transaction
. - The configuration of a provider for the
QuorumProvider
- Ws
legacy-ws
A JSON-RPC Client over Websockets.
Enums§
- Basic or bearer authentication in http or websocket transport
- A builder which implements
RawCall
methods for overridingeth_call
parameters. - DevRpcMiddlewareError
dev-rpc
DevRpcMiddleware Errors - Types of filters supported by the JSON-RPC.
- Error thrown when sending an HTTP request
- IpcError
ipc
and (Unix or Windows)Error thrown when sending or receiving an IPC message. - Errors while querying for logs
- Errors for the
MockProvider
- Helper response type for
MockProvider
, allowing custom JSON-RPC errors to be provided.Value
for successful responses,Error
for JSON-RPC errors. - Node Clients
- An error thrown when making a call to the provider
- Determines when the provider reached a quorum
- Error thrown when sending an HTTP request
- Error thrown when:
- Error thrown when using either read or write client
- WsClientError
legacy-ws
Error thrown when sending a WS message
Constants§
- addr(bytes32)
- The polling interval to use for local endpoints, See
crate::is_local_endpoint()
- The default polling interval for filters and pending transactions
- ENS registry address (
0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e
) - text(bytes32, string)
- supportsInterface(bytes4 interfaceID)
- name(bytes32)
Traits§
- CeloMiddleware
celo
Celo-specific extension trait - Trait which must be implemented by data transports to be used with the Ethereum JSON-RPC provider.
- Wrapper trait for
crate::JsonRpcClient
that erases generics and is object-safe. This trait is not intended for outside implementation - A middleware allows customizing requests send and received from an ethereum node.
MiddlewareError
is a companion trait tocrate::Middleware
. It describes error behavior that is common to all Middleware errors.- Extension trait for
Provider
- A transport implementation supporting pub sub subscriptions.
- Provides methods for overriding parameters to the
eth_call
rpc method - RetryPolicy defines logic for which JsonRpcClient::Error instances should the client retry the request and try to recover from.
- An
RpcError
is an abstraction over error types returned by acrate::JsonRpcClient
. - An extension trait for
Stream
s that provides a variety of convenient combinator functions.
Functions§
- Returns a number in bytes form with padding to fit in 32 bytes.
- Returns a transaction request for calling the
resolver
method on the ENS server - Create a stream that emits items at a fixed interval. Used for rate control
- Returns true if the endpoint is local
- Calls the future if
item
is None, otherwise returns afutures::ok
- Returns the ENS namehash as specified in EIP-137
- Returns the ENS record key hash EIP-634
- Returns a transaction request for calling
- Returns the reverse-registrar name of an address.
- Returns a transaction request for checking interface support
Type Aliases§
- A simple gas escalation policy