How to Convert ENS Address to ETH Address in JS

Shmoji
Coinmonks

--

Hello, in this tutorial I will show you the simplest example I can think of for how to convert an ENS address to an ETH address in your web app.

Knowing how to do this is valuable because most smart contracts only accept ETH addresses, not ENS addresses.

Resources

Intro

The simple answer for how to do this is that you just need to query the data from a subgraph. However, I’m going to go a bit more in detail.

There are multiple ways to convert an ENS address:

1: Using ENS.js

I used to use this library to convert ENS addresses. However, it does not work for applications that are on layer 2, so I will not be showing how to do it this way.

2: Using the decentralized subgraph offered by ENS

This is the most reliable method since it is decentralized. However, when I asked in the ENS discord, they said not to use this. Also, it would cost you money every time a user queries this subgraph on your app — so it’s not free. I think ENS eventually plans to tell everyone to use this subgraph, but I could be wrong and I’m not…

--

--