How to get ENS domain records for a given Ethereum wallet address

ENS, or Ethereum Name Service, is a distributed, open, and extensible naming system based on the Ethereum blockchain. ENS allows to map human-readable names like vitalik.eth to machine-readable identifiers such as Ethereum addresses, other cryptocurrency addresses, content hashes, and metadata (similar to DNS).

Mnemonic’s ENS resolution capabilities ensure builders can provide this experience to their users without the extra legwork of interacting with ENS to do reverse and forward lookups.

Mnemonic tracks any changes to the ENS domains and resolution of the domains to the corresponding addresses as it happens on the blockchain in order to provide the most up to date information.

In this tutorial, we’ll explore Mnemonic’s ENS reverse lookup capabilities. You’ll learn how to retrieve ENS domain records for a given Ethereum wallet address with just a single API call. Let’s jump in!

Using GetEntityByAddress to retrieve wallet addresses for a list of ENS domains

Mnemonic’s Foundational API offers two dedicated endpoints for forward and reverse lookup of ENS handles and wallet addresses, GetEntityByName, and GetEntityByAddress. Both endpoints allow you to resolve ENS handles or wallet addresses and get details on ENS records with ease.

In this tutorial, we want to retrieve the associated ENS domain(s) for a given Ethereum wallet address (reverse lookup) as such, we will use the GetEntityByAddress endpoint.

It requires only a single parameter: an Ethereum wallet address represented as a string.

Here is our query:

curlpythongo
Copy
Copied
curl -L -X GET 'https://ethereum.rest.mnemonichq.com/ens/v1beta1/entity/by_address/0xd8da6bf26964af9d7eed9e03e53415d37aa96045' \
-H 'X-API-Key: YOUR_API_KEY_HERE'
Copy
Copied
import requests # requires `pip install requests`
result = requests.get(
'https://ethereum.rest.mnemonichq.com/ens/v1beta1/entity/by_address/0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
    headers={'x-api-key': 'YOUR_API_KEY_HERE'}
).json()
Copy
Copied
package main
import (
  "fmt"
  "net/http"
  "io/ioutil"
)
func main() {
  reqUrl := "https://ethereum.rest.mnemonichq.com/ens/v1beta1/entity/by_address/0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
  req, _ := http.NewRequest("GET", reqUrl, nil)
  req.Header.Add("X-API-Key", "YOUR_API_KEY_HERE")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)
  fmt.Println(res)
  fmt.Println(string(body))
}

Our result will contain the following:

In addition to returning each of the associated ENS domains mapped to the wallet address you’re looking up, this query will retrieve the following details:

  • ENS Name: Human Readable string of the resolved (if known) ENS name
  • Mapping Creation Time (Block Timestamp):The block timestamp where the last address was set for this ENS name
  • Expiration Time of the ENS Mapping: Expiration Time of the ENS domain name (if it exists)

    Note: DNS names that have an ENS record do not have any expiration time.

  • Parent Domain: Resolved Domain name of the Parent node (if known) (for eg. Parent domain of “vitalik.eth” would be “eth”)

Here’s the results of our example request:

Copy
Copied
{
    "entities": [
        {
            "name": "vitalik.eth",
            "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "validFromTimestamp": "2021-02-15T17:19:09Z",
            "validTillTimestamp": "2032-05-03T21:50:24Z",
            "parentName": "eth"
        },
        {
            "name": "vitalik.takoyaki.eth",
            "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "validFromTimestamp": "2019-12-26T02:08:27Z",
            "validTillTimestamp": null,
            "parentName": "takoyaki.eth"
        },
        {
            "name": "vbuterin.stateofus.eth",
            "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "validFromTimestamp": "2018-10-26T22:43:39Z",
            "validTillTimestamp": null,
            "parentName": "stateofus.eth"
        },
        {
            "name": "vitalik.cannafam.eth",
            "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "validFromTimestamp": "2022-07-23T04:40:23Z",
            "validTillTimestamp": null,
            "parentName": "cannafam.eth"
        },
        {
            "name": "7860000.eth",
            "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
            "validFromTimestamp": "2022-06-24T11:37:16Z",
            "validTillTimestamp": "2023-05-26T12:42:21Z",
            "parentName": "eth"
        }
    ]
}

Now you know how to conduct a reverse lookup of an ENS domain using its associated wallet address with ease. This capability makes it easy to enable your users to use their wallet addresses and ENS domains interchangeably within your application.

P.S. Want to see the associated wallet address for a given ENS domain? Our GetEntityByName endpoint will do the trick. Check out this tutorial for more information.

We love feedback here at Mnemonic! After you’ve completed this tutorial, let us know about your experience or share feedback by tagging us on Twitter @mnemonichq or reaching out directly to our support@mnemonichq.com!