How to resolve a wallet address from an ENS name
Turn an ENS name like vitalik.eth into its 0x wallet address with the GoldRush API or viem, handle names that don't resolve, then fetch the wallet's balances.
On this page
- What ENS resolution is
- Prerequisites for resolving ENS names
- Step 1: Resolve a name with the GoldRush API
- Handle errors from the ENS Name Resolution API
- What the GoldRush ENS resolver supports
- Step 2: Use the address to fetch balances
- Alternative: resolve over RPC with viem
- Frequently asked questions
- Next steps
What ENS resolution is
The Ethereum Name Service (ENS) maps human-readable names such as vitalik.eth to machine addresses. Resolving a name means asking the ENS contracts which address the name currently points to, so your app can show, query or send to that address while the user only ever types the name.
Apps resolve names when a user:
- types a name into a search box or a "send to" field instead of pasting a 42-character hex address;
- connects or looks up a wallet by name, before you load its portfolio or transaction history;
- shares a profile link like
yourapp.xyz/vitalik.eththat has to load data for an address.
This guide covers forward resolution: name in, address out. It does it two ways, with the GoldRush ENS Name Resolution API and with viem over an Ethereum RPC, and then uses the address to fetch the wallet's token balances.
Prerequisites for resolving ENS names
- A GoldRush API key. Sign up to get one, and set it as
GOLDRUSH_API_KEYin your environment. - Node.js 18 or later and the GoldRush TypeScript SDK,
@covalenthq/client-sdk, plus viem if you want the RPC alternative:
npm install @covalenthq/client-sdk@3.0.9 viem@2.58.4- For the viem route only:
ETH_RPC_URL, an Ethereum mainnet JSON-RPC endpoint. - The examples are TypeScript with top-level
await. Save each one as an ES module file, such asresolve.mts, and run it withnpx tsx@4.23.15 resolve.mts; a plain.tsfile outside a"type": "module"project is compiled as CommonJS, where top-levelawaitfails.
Step 1: Resolve a name with the GoldRush API
The resolver endpoint takes a chain name and a registered name, and costs 1 per call:
curl "https://api.covalenthq.com/v1/eth-mainnet/address/vitalik.eth/resolve_address/" \ -H "Authorization: Bearer $GOLDRUSH_API_KEY"The response holds one item per resolved name, with the address under items[0].address. Here is a sample response for vitalik.eth, abridged:
{ "chain_id": 1, "chain_name": "eth-mainnet", "items": [ { "name": "vitalik.eth", "address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" } ]}With the SDK the same call is client.BaseService.getResolvedAddress(chain, name). Wrap it in a function that returns the address, or null when nothing comes back, so the rest of your app never has to dig through the response:
import { GoldRushClient } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY!); // Resolve a registered name to its address, or null if it has noneasync function resolveName(name: string): Promise<string | null> { const resp = await client.BaseService.getResolvedAddress("eth-mainnet", name); if (resp.error) throw new Error(`${resp.error_code} ${resp.error_message}`); return resp.data?.items?.[0]?.address ?? null;} const address = await resolveName("vitalik.eth");console.log(address);// 0xd8da6bf26964af9d7eed9e03e53415d37aa96045The SDK does not throw on API errors: it returns error, error_code and error_message next to data, so check error before you read the result.
Handle errors from the ENS Name Resolution API
The REST API returns errors in the same envelope as data: data is null, error is true, error_message says why, and error_code is the HTTP status as a number. The SDK passes the same three fields through on its response instead of throwing, which is what resolveName checks. The docs show this body for a chain name the API doesn't recognize:
{ "data": null, "error": true, "error_message": "Chain nosuchchain-mainnet not supported.", "error_code": 501 }A 501 won't change on retry: use one of the chains the resolver lists, eth-mainnet for ENS names. A wrong key returns a JSON 401; a request with no Authorization header at all gets an HTML 401 page from the edge proxy instead, so with curl, check the status before you parse the body. Failed requests cost no credits, and error handling lists every code.
What the GoldRush ENS resolver supports
- Names, not addresses. It does forward resolution only: a registered name to the address it points to. It does not look up the primary name for an address (reverse resolution). An unregistered name, or one with no address record, gives you no address; we haven't recorded whether that comes back as an error or as an empty
itemslist, soresolveNamehandles both. - ENS and other name services. The endpoint documents support for ENS, RNS (the RIF Name Service) and Unstoppable Domains names, and its path parameter also lists Lens handles.
- A short list of chains. The endpoint lists Ethereum (
eth-mainnet), Axie/Ronin (axie-mainnet), Base (base-mainnet), Polygon (matic-mainnet). For ENS names, useeth-mainnet.
Names change owners and records. Resolve when you need the address rather than storing the result forever, and show the resolved address to the user before anything irreversible, such as sending funds.
Step 2: Use the address to fetch balances
Once you have the address, pass it to any wallet endpoint. The ERC-20 token balance API returns every token the wallet holds on one chain, with prices, for 1 per call:
import { GoldRushClient } from "@covalenthq/client-sdk"; const client = new GoldRushClient(process.env.GOLDRUSH_API_KEY!);const address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; const resp = await client.BalanceService.getTokenBalancesForWalletAddress("eth-mainnet", address, { noSpam: true,});if (resp.error) throw new Error(`${resp.error_code} ${resp.error_message}`); for (const item of resp.data?.items ?? []) { console.log(item.contract_ticker_symbol, item.pretty_quote);}You can also skip the separate resolve step: the per-chain GoldRush wallet endpoints take a name wherever they take a wallet address and resolve it for you. The exception is the wallet balance API for balances across chains, which takes only a 0x address, so resolve the name first for that one. A request to the native token balance API (0.5 per call) for vitalik.eth returns the ETH balance with "address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" in the response. Call the resolver yourself when you want to show the address, cache it, or reuse it across several requests and chains.
For a full portfolio view built on these endpoints, see building a web3 portfolio tracker.
Alternative: resolve over RPC with viem
If your app already talks to an Ethereum node, you can resolve names directly against the ENS contracts with viem's getEnsAddress. It needs an Ethereum mainnet RPC endpoint, and the name should be normalized first:
import { createPublicClient, http } from "viem";import { mainnet } from "viem/chains";import { normalize } from "viem/ens"; const client = createPublicClient({ chain: mainnet, transport: http(process.env.ETH_RPC_URL) }); const address = await client.getEnsAddress({ name: normalize("vitalik.eth") });console.log(address); // null if the name has no address recordWhich to use:
- viem over RPC reads ENS itself, so it follows ENS behaviour as the protocol changes and needs no extra API. It resolves ENS only, and you run or pay for the RPC endpoint.
- The GoldRush API is one HTTP call with the same key you use for balances and transactions, and it also covers RNS and Unstoppable Domains names. If you are about to call GoldRush wallet endpoints anyway, you can pass the name straight to them.
Frequently asked questions
How do I get the wallet address for an ENS name?
Call the GoldRush resolver endpoint, /v1/eth-mainnet/address/{name}/resolve_address/, or client.BaseService.getResolvedAddress("eth-mainnet", name) in the TypeScript SDK, and read items[0].address from the response. With viem, call getEnsAddress with the normalized name on a mainnet client.
Can the GoldRush API look up the ENS name for an address?
No. The resolver endpoint only resolves a registered name to an address. For reverse resolution (the primary name of an address), read it from ENS directly, for example with viem's getEnsName.
Which name services does the resolver support?
The endpoint documents ENS, RNS and Unstoppable Domains names, and its address parameter also lists Lens handles. It resolves on Ethereum (eth-mainnet), Axie/Ronin (axie-mainnet), Base (base-mainnet), Polygon (matic-mainnet).
What happens if a name doesn't resolve?
You get no address: check that items has an entry before you use it, and check the SDK response's error field. Tell the user the name could not be resolved rather than falling back to another address.
Do I need to resolve a name before calling other GoldRush endpoints?
Usually not. The per-chain GoldRush wallet endpoints accept a name in place of the wallet address and resolve it themselves. The cross-chain wallet balance API does not accept names, so resolve first for it, and whenever you need the address itself for display, caching or reuse.
How much does a resolution cost?
Each call to the resolver endpoint costs 1 per call. See the ENS Name Resolution API reference for the current rate.
Next steps
- Read the ENS Name Resolution API reference for every parameter and response field.
- Fetch the resolved wallet's tokens with the ERC-20 token balance API, or across EVM chains in one call with the wallet balance API (pass it the resolved
0xaddress). - Learn how Ethereum addresses and accounts work in Ethereum accounts, addresses and wallets explained.
- New to GoldRush? Start with the Foundational API quickstart and the Foundational API overview.