Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
ENS (Ethereum Name Service): How Does it Work?
What is ENS?
ENS it’s name registrar and “DNS” in one, providing ability to register Ethereum names, get its owner info, expiration date, add “subdomains”, point them (resolve) to different addresses, etc…
So, registering name and keeping a record of its expiration — it’s what doing today any domain name registrar (like godaddy.com). Get info about name — that’s WHOIS service, and resolving names into addresses and reserve — that what is doing today DNS for us.
ENS handle all that stuff by itself.
Why we need it?
For the same purpose we use domain names, instead of typing IP address, we use domain name. As a wallet address is 42 character length strings, e.g. 0x5b854fc85bb7b2b3bdb78bd8dd85832121bd082c, it’s more convenient to use name instead, e.g. whoisens.eth
Names has .eth ending, and currently allowed min. 6 characters (we’ll discuss only .eth names).
How it works?
All that happens in Ethereum network by Smart Contracts. Smart Contract — it’s a code, once been deployed into network, working as micro-service, able to read and write data in blockchain. Since blockchain is immutable by its nature, so Smart Contracts — deployed code can’t be changed anymore. But you still able to read data from blockchain (for free) and write to it (paying for gas or other required fee if applied), thus making changes into ENS and read data from it.
Prior to a new ENS, name registration was made via auctions. Now, with a new ENS you can simply register name instantly by paying for it $5/year. All names that was registered via old ENS (via auction), should be transferred to new ENS till May 4, 2020. Otherwise they will be released, and available for registration for anybody.
Lets dive in
Before we jump into, let clarify a few terms:
- Registrar — it’s who register your name. It’s like godaddy.com. It will store all info about name owner and its expiration.
- Resolver — smart contract which resolves name into address or reverse. It could be public or custom one. Similar to name servers in DNS.
- Owner of name — person who possess that name. Can do anything with it
- Controller of name — person who has rights to make changes into that name, e.g. add subdomains, change resolvers, etc… Owner can delegate such rights, thus, still be owner of that name, delegate rights to make changes
- Domain — the complete, human-readable form of a name, e.g. ‘scirott.eth’
- Label — a single component of a domain, e.g. ‘scirott’, ‘eth’
Lets look into provided diagram for mainnet below for example name:
ENS Diagram for scirott.eth example name
In yellow color — it’s deployed Smart Contracts. In blue — their methods.
In diagram you can see two types of hashing — node and hash.
node — it’s name hash function as per EIP-137. hash — it’s keccak-256 of SHA3 hash function.
The start point — it’s ENS Eth Name Service. Address is published in official site.
Get owner information
- get top level label for our name — node(‘eth’)
- call method owner — it will return address of Base Registrar smart contract.
- Now using hash for our name label we can get name owner (ownerOf) and expiration date (nameExpires).
- Calling owner method from ENS Eth Name Service will return us Controller.
Resolving name/address
- get node for our name
- calling resolver method of the same ENS Eth Name Service will return Resolver address (forward resolver). In our case it’s public resolver.
- calling addr method returns address for our name
- calling contenthash method returns content for our name. It could be Swarm (bzz://) or IPFS (ipfs://). Content hash described in EIP-1157.
- Using the same resolver method we can get reverse record. Name should be compose from address + ‘addr.reverse’ string, e.g. f304….5ad9.addr.reverse. Calling that method — will return contract address (reverse resolver), and calling name method — will return name if record presented in ENS. We have exactly the same functionality in DNS nowadays.
Useful links
You can register your own Ethereum name in official ENS site.
You can use Whois ENS to look up for names/addresses. It has advanced output, including contract addresses and methods. Note, that it works only with new ENS register names.
If you need ENS name resolver, and don’t use any third party web3.js or similar, you can use whoisens-lib for that or WhoisENS REST API.
P.S. If you find some incorrect info provided in article, please let me know.
ENS (Ethereum Name Service): How it works? was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.