How to Resolve a Wallet Address Given an ENS Domain

This guide focuses on leveraging the GoldRush API to convert Ethereum Name Service (ENS) domains into corresponding wallet addresses.

Integrating human-readable names into blockchain applications is essential for user-friendly interactions. This guide focuses on leveraging the GoldRush API to convert Ethereum Name Service (ENS) domains into corresponding wallet addresses, enhancing the usability of dApps.

Introduction to ENS Domains

ENS domains simplify the process of sending and receiving cryptocurrencies by providing memorable, human-readable aliases for complex blockchain addresses. This functionality mirrors the ease of use seen with internet domain names, making blockchain transactions more accessible to the average user.

For instance, when looking up your wallet address on a block explorer, sending money to a friend, or claiming an NFT, it is much easier to put in your ENS domain than to find, copy and paste your lengthy hexadecimal address.

The Importance of Resolving ENS Domains

Resolving ENS domains to their corresponding wallet addresses is vital for applications aiming to streamline user interactions. This process not only verifies wallet ownership but also ensures transactions are sent to the correct addresses without needing users to input or remember lengthy alphanumeric strings.

From a developer’s standpoint, resolving an ENS domain is often the first step before querying and displaying a user’s onchain activity like their portfolio or transaction history.

Prerequisites

Before proceeding, make sure you have:

  • Node.js installed on your machine.

  • Acquired a GoldRush API key by signing up on the GoldRush website.

In this tutorial, we are using this endpoint:

Get resolved address for registered address

Commonly used to resolve ENS, RNS and Unstoppable Domains addresses.

Tutorial: Finding the Corresponding Wallet Address for a Given ENS Domain

1

Installation

Install the GoldRush client SDK to interact with the GoldRush API. In your terminal, execute:
This installs the necessary libraries for your application.
npm install @covalenthq/client-sdk
2

Setting Up the GoldRush API Endpoint

To resolve an ENS domain to a wallet address, use the GoldRush API endpoint:
/v1/{chainName}/address/{walletAddress}/resolve_address/
This versatile endpoint supports ENS, RNS (RIF Name Service), and Unstoppable Domains, offering a comprehensive solution for various blockchain name services.
3

Implementing the Resolution Code

In a new JavaScript file, import the GoldRush client SDK. Adapt the following snippet to resolve a wallet address from an ENS domain:
Make sure to replace "Your_Covalent_API_Key" with your actual API key and "your_ens_domain.eth" with the ENS domain you're resolving.
import { CovalentClient } from "@covalenthq/client-sdk";

const ApiServices = async () => {
    const client = new CovalentClient("Your_Covalent_API_Key");
    const chainName = "eth-mainnet"; // Specify the blockchain
    const ensDomain = "your_ens_domain.eth"; // ENS domain to resolve
    // Convert the ENS domain to a wallet address
    const resp = await client.BaseService.getResolvedAddress(chainName, ensDomain);
    console.log("Resolved Wallet Address:", resp.data);
};
ApiServices().catch(console.error);
4

Running Your Code

To execute your script and see the wallet address resolution in action, run:
This will print the corresponding wallet address of the provided ENS domain to the console.
node your_file_name.js

Understanding the Response

Here is an example of what your console output will look like, using the ENS domain demo.eth.

Resolved Wallet Address: 0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de

This output directly corresponds to the address field of the first item in the items array from the API response, showcasing the wallet address associated with the queried ENS domain demo.eth. Here is what the full JSON response from the endpoint looks like, where you can see the address field:

data: { updated_at: "2024-03-18T17:58:43.724743155Z", chain_id: 1, chain_name: "eth-mainnet", items: [ { name: "demo.eth", address: "0xfc43f5f9dd45258b3aff31bdbe6561d97e8b71de" } ], pagination: null },

Conclusion

Incorporating ENS domain resolution into your application facilitates a smoother, more intuitive user experience. Following this guide allows developers to efficiently implement this feature, leveraging the GoldRush API's capabilities to enhance user interactions within the blockchain ecosystem.

Read more