Introducing Ethereum Name Service: Blockchain’s DNS

Tram Ho

Etherum in particular as well as blockchain platforms, other cryptocurrencies in particular are not really popular with ordinary users. The reason is partly because blockchain technology or crypto currency is still very new, partly because it is not really user friendly (long wallet address, hard to remember, backup private key, …). The Ethereum Name Service (ENS) was created to solve this problem, mapping long wallet addresses into a short name that is easier to remember.

1. Introduction

The Ethereum Name Service is simply a distributed domain service on the Ethereum platform. The ENS function is similar to DNS (mapping IP addresses to more memorable domains). Like DNS, ENS deploys on a hierarchical domain system of domains and subdomains, the owner of a domain has full control over subdomains. For example, domain .eth , subdomain will be foo.eth , bar.eth ….

The logic of ENS is shown in the smart contract ENS and deployed to the Ethereum network (or test networks). If the terminal application uses the ethereum-ens library, it will automatically detect the network and use ENS on that network.

2. Architecture

ENS has 2 main parts:

The ENS registry is a smart contract that contains lists of domains and subdomains. Each domain or subdomains store the following 3 information:

  • The owner address of the domain or subdomains
  • Address resolver of domain or subdomains
  • Term of domains

The owner of a domain has the right:

  • Specify the resolvers and duration of the domains
  • Transfer domain ownership to another address
  • Change owner of subdomains

You can see the source code of ENS Registry contract here

Resolvers is simply the place to perform the domains => address conversion and return the address corresponding to the domain for the user.

The process consists of 2 steps as shown above:

  • B1: The application asks for the address of resolvers of domains foo.eth by calling resolvers . The registry will return the address of the corresponding resolvers
  • B2: The application calls resolvers to get the address corresponding to the foo.eth domains

3. Integrating ENS into Dapp

ENS Libraries

ENS support supports many libraries with different languages. The most popular is still Javascript.

Only the ethereum-ens library is officially supported by the full ENS developer team. Other libraries are more or less restricted at some point.

web3.js does not support creating domains, transferring domain owners (transferring ownership) or changing resolvers (updating resolvers).

ethjs-ens only supports forward and name resolution of ENS domain.

Similar to ethjs-ens is ethers.js .

Create an ENS domain

Creating a domain on the mainnet Ethereum will lose ETH so we create a new domain on the testnet. Here I choose Rinkeby’s network. The process of creating a domain consists of 3 steps.

After successful creation, display the basic information of the domain.

Working with ENS

Before you can start interacting with ENS, we will need to get a reference to the ENS registry.

The results returned using web3-js are as follows:

Decode ENS domain into address

Example with web3-js:

Address resolution to ENS domain

Domain name management

Change domain owner

Create subdomains

4. Demo

In this section, we will write a simple Dapp that functions:

  • Send ETH to another account via regular address
  • Send ETH to another account via ENS domain name

Initialize the directory and install the necessary packages

GetWeb3

Writing Component

  • There are 2 input boxes for the user to enter the address and ether number to send
  • Check box Use ENS Domain help users optionally sent via ENS Domain or not?
  • If sent through the ENS Domain , the ethereum-ens library will resolve the domain and return the address on the network, then send the ether via web3 as usual.

We try sending 0.00001 ether to the domain conglt.eth

Submitted successfully ?

Note :

  • You can refer to the full source code on Github
  • The demo is deployed on Surge

References

https://docs.ens.domains/

Share the news now

Source : Viblo