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;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_rpcdev-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_wslegacy-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 by CallBuilder::new.
DevRpcMiddlewaredev-rpc
DevRpcMiddleware
EscalatingPending
An EscalatingPending is a pending transaction that increases its own gas price over time, by broadcasting successive versions with higher gas prices.
FilterWatcher
Streams data from an installed filter via eth_getFilterChanges
Http
A low-level JSON-RPC Client over HTTP.
HttpRateLimitRetryPolicy
Implements RetryPolicy that will retry requests that errored with status code 429 i.e. TOO_MANY_REQUESTS
Ipcipc and (Unix or Windows)
A JSON-RPC Client over Unix IPC.
JsonRpcError
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 or Middleware::subscribe_logs
Map
An implementer of RawCall that maps a function f over the output of the inner future.
MockProvider
Mock transport used in test environments.
NodeInfo
This includes general information about a running node, spanning networking and protocol details.
PeerInfo
Represents a short summary of information known about a connected peer.
PendingTransaction
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 enough confirmations. The default number of confirmations is 1, but may be adjusted with the confirmations 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.)
QuorumProvider
A provider that bundles multiple providers and only returns a value to the caller once the quorum has been reached.
RetryClient
RetryClient presents as a wrapper around JsonRpcClient that will retry requests based with an exponential backoff and filtering based on RetryPolicy.
RetryClientBuilder
Builder for a RetryClient
RwClient
A client containing two clients.
SubscriptionStream
Streams data from an installed filter via eth_subscribe
TransactionStream
Drains a stream of transaction hashes and yields entire Transaction.
WeightedProvider
The configuration of a provider for the QuorumProvider
Wslegacy-ws
A JSON-RPC Client over Websockets.

Enums§

Authorization
Basic or bearer authentication in http or websocket transport
CallBuilder
A builder which implements RawCall methods for overriding eth_call parameters.
DevRpcMiddlewareErrordev-rpc
DevRpcMiddleware Errors
FilterKind
Types of filters supported by the JSON-RPC.
HttpClientError
Error thrown when sending an HTTP request
IpcErroripc and (Unix or Windows)
Error thrown when sending or receiving an IPC message.
LogQueryError
Errors while querying for logs
MockError
Errors for the MockProvider
MockResponse
Helper response type for MockProvider, allowing custom JSON-RPC errors to be provided. Value for successful responses, Error for JSON-RPC errors.
NodeClient
Node Clients
ProviderError
An error thrown when making a call to the provider
Quorum
Determines when the provider reached a quorum
QuorumError
Error thrown when sending an HTTP request
RetryClientError
Error thrown when:
RwClientError
Error thrown when using either read or write client
WsClientErrorlegacy-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§

CeloMiddlewarecelo
Celo-specific extension trait
JsonRpcClient
Trait which must be implemented by data transports to be used with the Ethereum JSON-RPC provider.
JsonRpcClientWrapper
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.
MiddlewareError
MiddlewareError is a companion trait to crate::Middleware. It describes error behavior that is common to all Middleware errors.
ProviderExt
Extension trait for Provider
PubsubClient
A transport implementation supporting pub sub subscriptions.
RawCall
Provides methods for overriding parameters to the eth_call rpc method
RetryPolicy
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 a crate::JsonRpcClient.
StreamExt
An extension trait for Streams 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 a futures::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§

EscalationPolicy
A simple gas escalation policy