Skip to content
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ significant_drop_tightening = "allow"
needless_return = "allow"

[workspace.dependencies]
alloy = { version = "1.0.41", features = [
alloy = { version = "1.1.0", features = [
"eips",
"ens",
"full",
"json-rpc",
"node-bindings",
Expand Down
20 changes: 20 additions & 0 deletions examples/ens/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "examples-ens"
publish.workspace = true
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

eyre.workspace = true
futures-util.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
20 changes: 20 additions & 0 deletions examples/ens/examples/address_lookup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Example of looking up ENS names from Ethereum addresses.
use alloy::{ens::ProviderEnsExt, primitives::address, providers::ProviderBuilder};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
// Create a provider.
let rpc_url = "https://reth-ethereum.ithaca.xyz/rpc".parse()?;
let provider = ProviderBuilder::new().connect_http(rpc_url);

// Vitalik's Ethereum address.
let vitalik_address = address!("0xd8da6bf26964af9d7eed9e03e53415d37aa96045");

// Perform reverse ENS lookup to get the ENS name for the address.
let ens_name = provider.lookup_address(&vitalik_address).await?;

println!("Address {vitalik_address} resolves to: {ens_name:?}");

Ok(())
}
18 changes: 18 additions & 0 deletions examples/ens/examples/name_resolution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Example of resolving ENS names to Ethereum addresses.

use alloy::{ens::ProviderEnsExt, providers::ProviderBuilder};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
// Create a provider.
let rpc_url = "https://reth-ethereum.ithaca.xyz/rpc".parse()?;
let provider = ProviderBuilder::new().connect_http(rpc_url);

// Resolve the ENS name "vitalik.eth" to its Ethereum address.
let address = provider.resolve_name("vitalik.eth").await?;

println!("vitalik.eth resolves to: {address:?}");

Ok(())
}
Loading