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

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 forward lookup capabilities. You’ll learn how to resolve Ethereum wallet addresses (and mapping details) from an ENS domain with just a single API call. Let’s jump in!

Using GetEntityByName 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 with ease.

In this tutorial, we want to retrieve the wallet address of an ENS domain (forward lookup) as such, we will use the GetEntityByName endpoint.

It requires only a single parameter: an ENS domain represented as a string.

Here is our query:

curlpythongo
Copy
Copied
curl -i -X GET \
  'https://ethereum.rest.mnemonichq.com/ens/v1beta1/entity/by_name/vitalik.eth' \
  -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_name/vitalik.eth',
    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_name/vitalik.eth"
  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:

  • ENS Name: Human readable string of the ENS name you’ve resolved
  • Wallet Address: Resolved address of the given 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
{
    "entity": {
        "name": "vitalik.eth",
        "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
        "validFromTimestamp": "2021-02-15T17:19:09Z",
        "validTillTimestamp": "2032-05-03T21:50:24Z",
        "parentName": "eth"
    }
}

Now you know how to conduct a forward lookup of an ENS domain and return 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 ENS domains for a given wallet address (reverse lookup)? Our GetEntityByAddress 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!