41 releases (15 stable)

2.0.13 Jan 30, 2024
2.0.11 Nov 16, 2023
2.0.10 Sep 7, 2023
2.0.8 Jul 15, 2023
0.1.3 Jun 20, 2020

#1379 in Magic Beans

Download history 28150/week @ 2023-10-30 29200/week @ 2023-11-06 32543/week @ 2023-11-13 35473/week @ 2023-11-20 44318/week @ 2023-11-27 45259/week @ 2023-12-04 42050/week @ 2023-12-11 40216/week @ 2023-12-18 22218/week @ 2023-12-25 32129/week @ 2024-01-01 46595/week @ 2024-01-08 48537/week @ 2024-01-15 48984/week @ 2024-01-22 79819/week @ 2024-01-29 59641/week @ 2024-02-05 52744/week @ 2024-02-12

243,682 downloads per month
Used in 179 crates (27 directly)

MIT/Apache

1.5MB
27K SLoC

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

# use ethers_core::types::Address;
# use ethers_providers::{Provider, Http, Middleware, Ws};
# async fn foo() -> Result<(), Box<dyn std::error::Error>> {
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)?);
# Ok(())
# }

Using ENS:

# use ethers_providers::{Provider, Http, Middleware};
# async fn foo() -> Result<(), Box<dyn std::error::Error>> {
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());
# Ok(())
# }

Dependencies

~21–40MB
~722K SLoC