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.
Read the guide on How to Resolve a Wallet Address Domains Given an ENS.
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?
- Create a free Alchemy account to get an API Key
- Select an ENS to resolve to a Wallet Address (i.e. “vitalik.eth”)
- Alchemy SDK (recommended)
How does ENS work?web
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.
2. Install the Alchemy SDK
Navigate into your project directory and run:
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.
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
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:
And that’s it! You can now easily get a Wallet Address for any given ENS domain 🎉