3. Using the Ethereum Name Service

In the previous lesson, you learned about smart contracts and how to connect to them. The next step is to make this work easier with ENS.

You learned that addresses are to the blockchain what IPs are to the internet. The same goes for the Ethereum Name Service, short ENS. It's the blockchain equivalent of the Domain Name Service, or DNS.

ENS can be used to make addresses more accessible for humans. This way you can connect to EOAs and smart contracts with a human readable string.

You can register ENS domains just like regular domains at the ENS service website.

Reading a Contract's Balance

Ethers.js works transparently with ENS, so we can simply replace the address from the last lesson with an ENS domain that resolves to that address. In case of that address a corresponding domain is devdao.eth.

Try it in the editor. Fetch the balance of the Developer DAO NFT contract and print it. But use the devdao.eth ENS domain instead of the address!

const provider = ethers.getDefaultProvider() // write your code here!

const balance = await provider.getBalance("devdao.eth") print(ethers.utils.formatUnits(balance) + " ETH")

Note: Keep in mind, the target blockchain address of a ENS domain can change. So if you want to make sure that the same address is called every time, use the address directly.

Conclusion

ENS domains are a usability imporvement for the blockchain. Just like DNS domains were for the internet in general. Remembering devdao.eth is much easier than a big hex number.

Ethers.js works transparently with ENS domains, so you can usually drop-in a domain in places where you need an address.

In the next lesson, we will learn about Ethereum Request for Comments, or short ERCs.