ENS (Ethereum Name Service): How Does it Work?

Alex Ivasyuv
3 min readMay 25, 2019

--

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

  1. get top level label for our name — node(‘eth’)
  2. call method owner — it will return address of Base Registrar smart contract.
  3. Now using hash for our name label we can get name owner (ownerOf) and expiration date (nameExpires).
  4. Calling owner method from ENS Eth Name Service will return us Controller.

Resolving name/address

  1. get node for our name
  2. calling resolver method of the same ENS Eth Name Service will return Resolver address (forward resolver). In our case it’s public resolver.
  3. calling addr method returns address for our name
  4. calling contenthash method returns content for our name. It could be Swarm (bzz://) or IPFS (ipfs://). Content hash described in EIP-1157.
  5. 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.

--

--