Understanding ENS Domain Resolution
The Ethereum Name Service (ENS) simplifies blockchain interactions by replacing complex hexadecimal addresses with human-readable domain names. This guide explores the technical process of resolving ENS domains to various resources, focusing on Ethereum addresses while also covering advanced use cases.
Resolving to Ethereum Addresses
The most common ENS operation is resolving a domain name to an Ethereum address. Here's how various libraries handle this process:
Library-Specific Implementations
ethereum-ens
var address = await ens.resolver('alice.eth').addr();
web3.js
var address = ens.getAddress('alice.eth');
ethjs-ens
var address = await ens.lookup('alice.eth');
ethers.js
var address = await provider.resolveName('alice.eth');
๐ Learn more about Ethereum development tools
Manual Resolution Process
For developers not using ENS libraries, resolution requires three steps:
- Normalize and hash the target domain name
- Call
resolver()
on the ENS registry with the namehash - Call
addr()
on the resolver contract with the namehash
Multi-Coin Address Resolution
ENS supports cryptocurrency addresses beyond Ethereum through overloaded addr()
functions:
- Use the domain's namehash with SLIP44-compliant chain IDs
- Bitcoin example:
addr(hash, 0)
- Binary-formatted addresses require EIP-2304 decoding
Warning: Always treat 0x00...00 responses from addr()
as unset records to prevent fund loss.
Resolving to Non-Address Resources
ENS domains can resolve to diverse resource types:
- Content hashes (Swarm/IPFS)
- Contract ABIs
- Text-based metadata
- Decentralized website pointers
Resolution follows the same 3-step process, substituting addr()
with resolver functions specific to each resource type.
Reverse Resolution Explained
Reverse resolution maps addresses back to domain names, enabling human-friendly displays in applications.
Implementation Overview
- Special
addr.reverse
domain handles reverse records - Dedicated registrar allocates subdomains to address owners
- Resolver's
name()
function retrieves associated domains
๐ Explore advanced ENS features
Library Examples
ethereum-ens
const address = '0x1234...';
var name = await ens.reverse(address).name();
if(address != await ens.resolver(name).addr()) {
name = null;
}
ethers.js
var address = '0x1234...';
var name = await provider.lookupAddress(address);
// Automatic forward resolution check
Critical Security Note
Always verify reverse records by:
- Performing forward resolution on returned names
- Confirming the original address matches
- Treating unverified records as invalid
Frequently Asked Questions
How does ENS differ from DNS?
ENS operates on Ethereum blockchain, providing decentralized domain resolution with cryptocurrency support and smart contract integration.
Can I use ENS for non-Ethereum cryptocurrencies?
Yes, ENS supports multi-coin address resolution including Bitcoin (BTC) through specialized resolver functions.
Is reverse resolution mandatory for ENS domains?
No, reverse resolution is optional but recommended for improving user experience in applications.
What happens if two people claim the same reverse record?
ENS doesn't enforce reverse record accuracy. Always verify through forward resolution to prevent spoofing.
Can ENS domains point to IPFS content?
Yes, ENS supports contenthash records that can resolve to IPFS, Swarm, or other decentralized storage hashes.
How do I update my resolver contract?
Resolver contracts are upgradable through ENS registry calls, allowing for future protocol improvements.