gleeth/ens
ENS (Ethereum Name Service) resolution.
Resolves human-readable .eth names to Ethereum addresses (forward)
and addresses back to names (reverse) by querying the ENS registry
and resolver contracts on-chain.
Examples
// Forward: name -> address
let assert Ok(address) = ens.resolve(provider, "vitalik.eth")
// Reverse: address -> name
let assert Ok(name) = ens.reverse_resolve(provider, "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
Values
pub fn decode_abi_string(
result_hex: String,
) -> Result(String, types.GleethError)
ABI-decode a string from RPC return data. Layout: offset(32 bytes) + length(32 bytes at offset) + data. Shared between ENS and permit modules.
pub fn namehash(name: String) -> BitArray
Compute the ENS namehash for a domain name.
The namehash algorithm recursively hashes labels:
namehash("") = 0x00...00
namehash("eth") = keccak256(namehash("") + keccak256("eth"))
namehash("vitalik.eth") = keccak256(namehash("eth") + keccak256("vitalik"))
Examples
let hash = ens.namehash("vitalik.eth")
pub const registry_address: String
ENS Registry address (same on mainnet, Goerli, Sepolia).
pub fn resolve(
provider: provider.Provider,
name: String,
) -> Result(String, types.GleethError)
Resolve an ENS name to an Ethereum address.
Queries the ENS registry for the resolver, then queries the resolver for the address. Returns an error if the name has no resolver or no address set.
Examples
let assert Ok(addr) = ens.resolve(provider, "vitalik.eth")
pub fn reverse_resolve(
provider: provider.Provider,
address: String,
) -> Result(String, types.GleethError)
Reverse resolve an Ethereum address to its primary ENS name.
Computes the reverse node (<addr>.addr.reverse), queries the ENS
registry for the reverse resolver, then calls name(bytes32) on it.
Examples
let assert Ok(name) = ens.reverse_resolve(
provider,
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
)
// name = "vitalik.eth"