Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Address Lookup

Resolve blockchain addresses from human-readable names with ENS.

A forward lookup takes an ENS name and returns its address. Use this wherever a user can enter a recipient, including payments and messaging.

nick.eth
nick.eth0x0000...0000

Treat all valid dot-separated names as potential ENS names, since ENS supports many TLDs.

Getting the User's Ethereum Address

Use a library that resolves through the Universal Resolver. The examples require viem 2.35.0 or later, ethers 6.17.0 or later, ENSjs 4.2.3 or later, web3.py 7.16.0 or later, or alloy-rs 2.4.2 or later. See ENSv2 library support for the full list.

Replace <MAINNET_RPC_URL> with your Ethereum Mainnet RPC endpoint in each example.

These examples resolve nick.eth. Replace it with the normalized user input in your application. A name's records can change, so use the returned address rather than a cached example value.

The Wagmi examples were tested with Wagmi 2.19.5 and viem 2.57.10. Configure WagmiProvider with Ethereum Mainnet and wrap your app in QueryClientProvider, as described in the Wagmi setup guide.

Wagmi
import { normalize } from 'viem/ens'
import { useEnsAddress } from 'wagmi'
 
export function Address() {
  const { data, isPending, error } = useEnsAddress({
    name: normalize('nick.eth'),
    chainId: 1,
  })
 
  if (isPending) return <span>Loading…</span>
  if (error) return <span>Lookup failed</span>
  return <span>{data ?? 'No address set'}</span>
}

A name may have no address record. Handle that result before using it as a transaction recipient. To learn what happens under the hood, read Resolution.

Multichain Addresses

ENS names can store addresses for Ethereum L2s and other blockchains. Use a SLIP-0044 coin type for non-EVM networks. For EVM chains other than Ethereum Mainnet, derive the coin type from the chain ID using ENSIP-11, even if the chain also has a SLIP-0044 entry.

These examples request the Base address for gregskril.eth. The viem example also requests the Bitcoin record as bytes.

Wagmi
import { toCoinType } from 'viem'
import { base } from 'viem/chains'
import { normalize } from 'viem/ens'
import { useEnsAddress } from 'wagmi'
 
export function BaseAddress() {
  const { data, isPending, error } = useEnsAddress({
    name: normalize('gregskril.eth'),
    coinType: toCoinType(base.id),
    chainId: 1,
  })
 
  if (isPending) return <span>Loading…</span>
  if (error) return <span>Lookup failed</span>
  return <span>{data ?? 'No address set'}</span>
}
NetworkCoin Type
Bitcoin0
Litecoin2
Dogecoin3
Ethereum60
Solana501
OP Mainnet2147483658
Polygon2147483785
Base2147492101
Arbitrum One2147525809

Decoding Address Records

Resolvers return address records as bytes. Some libraries decode them for you. Viem's getEnsAddress returns hex-encoded bytes, so decode non-EVM records into the destination chain's address format before displaying or using them. The address-encoder package provides coin-specific decoders.

Advanced

In-Depth ResolutionLearn how the Universal Resolver finds and reads records.
Advanced