Crate ethers_providers

source ·
Expand description

Clients for interacting with Ethereum nodes

This crate provides asynchronous Ethereum JSON-RPC compliant clients.

For more documentation on the available calls, refer to the Provider struct.

Examples

use ethers_core::types::Address;
use ethers_providers::{Provider, Http, Middleware};
use std::convert::TryFrom;

let provider = Provider::<Http>::try_from(
    "https://mainnet.infura.io/v3/YOUR_API_KEY"
)?;

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)?);

Websockets

The crate has support for WebSockets via Tokio. Please ensure that you have the “ws” and “rustls” / “openssl” features enabled if you wish to use WebSockets.

let ws = Ws::connect("ws://localhost:8545").await?;

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 mainnet and can be overriden by calling the ens method on the provider.

// 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;

Modules

Overrides for the eth_call rpc method
ERC related utilities. Only supporting NFTs for now.
Pre-instantiated Infura HTTP clients which rotate through multiple API keys to prevent rate limits

Structs

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
Unix Domain Sockets (IPC) transport.
Mock transport used in test environments.
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.
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.
A client contains 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
A JSON-RPC Client over Websockets.

Enums

Basic or bearer authentication in http or websocket transport
Types of filters supported by the JSON-RPC.
Error thrown when sending an HTTP request
Error thrown when sending or receiving an IPC message.
Errors for the MockProvider
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
Error thrown when sending a WS message

Constants

The polling interval to use for local endpoints, See crate::is_local_endpoint()
The default polling interval for filters and pending transactions

Traits

Trait which must be implemented by data transports to be used with the Ethereum JSON-RPC provider.
A middleware allows customizing requests send and received from an ethereum node.
Extension trait for Provider
A transport implementation supporting pub sub subscriptions.
RetryPolicy defines logic for which JsonRpcClient::Error instances should the client retry the request and try to recover from.
An extension trait for Streams that provides a variety of convenient combinator functions.

Functions

Returns true if the endpoint is local
Calls the future if item is None, otherwise returns a futures::ok

Type Definitions

A simple gas escalation policy