Clients for interacting with Ethereum nodes.
This crate provides asynchronous Ethereum JSON-RPC compliant clients.
For more information, please refer to the book.
This crate supports for WebSockets via tokio-tungstenite
.
Please ensure that you have the ws
feature enabled if you wish to use WebSockets:
toml
[dependencies]
ethers-providers = { version = "2.0", features = ["ws"] }
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:
toml
[dependencies]
ethers-providers = { version = "2.0", features = ["ipc"] }
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.
```rust,no_run
let provider = Provider::
let block = provider.getblock(100u64).await?; println!("Got block: {}", serdejson::to_string(&block)?);
let addr = "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359".parse::
()?; let code = provider.getcode(addr, None).await?; println!("Got code: {}", serdejson::to_string(&code)?);```
Using ENS:
```rust,no_run
let provider = Provider::
// Resolve ENS name to Address let name = "vitalik.eth"; let address = provider.resolve_name(name).await?;
// Lookup ENS name given Address let resolvedname = provider.lookupaddress(address).await?; asserteq!(name, resolvedname);
/// Lookup ENS field let url = "https://vitalik.ca".tostring(); let resolvedurl = provider.resolvefield(name, "url").await?; asserteq!(url, resolved_url);
/// Lookup and resolve ENS avatar let avatar = "https://ipfs.io/ipfs/QmSP4nq9fnN9dAiCj42ug9Wa79rqmQerZXZch82VqpiH7U/image.gif".tostring(); let resolvedavatar = provider.resolveavatar(name).await?; asserteq!(avatar, resolvedavatar.tostring());
```