How to Resolve a Wallet Address Given an ENS Domain

In this tutorial, we’ll be using Alchemy’s core API to resolve a user's address from an ENS Domain Name owned by the user.

If you just need the script for this tutorial refer to the below Recipe or continue reading for more

The Alchemy SDK makes it possible to parse ENS names from an address and perform the reverse to resolve the address of an ENS name. This latter case is useful when there's a need to get more data from an (Address), such as contracts which have been deployed by the EOA.

In this guide, we walk you through how to resolve a Wallet Address from an ENS.

What tools do you need to resolve an ENS name to a Wallet Address?

  1. Create a free Alchemy account to get an API Key
  2. Select an ENS to resolve to a Wallet Address (i.e. “vitalik.eth”)
  3. AlchemyWeb3.js (recommended)

How does ENS work?

Ethereum Name Service (ENS) takes the exact concept as the Domain Name Service (DNS) but adjusts it for the needs of Ethereum users. The (ENS)’s job is to map human-readable names like ‘alice.eth’ to machine-readable identifiers such as Ethereum addresses, other cryptocurrency addresses, content hashes, and metadata. We’ll be using npm in this example.

1. Create a new repository with Alchemy's API

Open up a terminal, and from the command line, create a new repository to hold your quickstart scripts. We'll also initialize the repo as an npm project.

mkdir alchemy-resolve-ens
cd alchemy-resolve-ens
npm init --yes

2. Install the Alchemy SDK

Navigate into your project directory and run:

npm install alchemy-sdk

3. [optional] Load ES6 modules

If you run into module errors, you may need to add 'type':'module' to your package.json because we'll be utilizing import syntax to load ES6 modules in our script.

{
...
"type": "module"
}

4. Write script using resolveName to resolve a Wallet address from an ENS domain.

In this example we'll resolve the address for the ENS name: vitalik.eth

Create a file in your repository called resolve-ens.js and paste in the following

// Setup: npm install alchemy-sdk
import { Alchemy, Network } from "alchemy-sdk";

const config = {
  apiKey: "<-- ALCHEMY APP API KEY -->",
  network: Network.ETH_MAINNET,
};
const alchemy = new Alchemy(config);

alchemy.core.resolveName("vitalik.eth").then(console.log);

5. Print ENS objects

From the command line, run node resolve-ens.js

The resolveName method takes in the ENS domain as a string and logs it to the console. The ENS address for vitalik.eth in this instance resolves to:

0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045

And that's it! You can now easily get a Wallet Address for any given ENS domain :tada: