ENS Logo
Docs

Lookup Address

The ENS Protocol aims to make it easy to use Ethereum. It does this by providing a simple way to use human-readable names instead of long machine-readable addresses.

Getting the users Ethereum Address
Forward Lookup

The goal here is to take a name, such as nick.eth, and convert it to an address, such as 0x225f137127d9067788314bc7fcc1f36746a3c3B5.

luc.eth➡️0x225...c3B5

The simplest thing you can do is start with a name, and resolve it to an address. We call this a "forward lookup". Think of places where users can enter names, such as sending transactions, chatting, etc.

Forward Resolution
import { useAccount, useEnsName, useEnsAvatar } from "wagmi";

export const Name = () => {
    const { data: ensName } = useEnsAddress({
        address: "luc.eth", // The name to lookup
        chainId: 1, // The chainId to lookup on
    });

    return <div>{ensName || address}</div>;
};
const address = await provider.lookupAddress("luc.eth");
import { normalize } from "viem/ens";
import { publicClient } from "./client";

const ensAddress = await publicClient.getEnsAddress({
    name: normalize("luc.eth"),
});
let provider = Provider::<Http>::try_from("https://mainnet.infura.io/v3/...")?;

let address = provider.lookup_address("luc.eth").await?;
package main

import (
	"fmt"

	"github.com/ethereum/go-ethereum/ethclient"
	ens "github.com/wealdtech/go-ens/v3"
)

func main() {
	client, _ := ethclient.Dial("https://rpc.ankr.com/eth")

	domain, _ := ens.Normalize("luc.eth")
	resolver, _ := ens.NewResolver(client, domain)
	address, _ := resolver.Address()

	fmt.Println("Address:", address.Hex())
}
// 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);
import { http } from 'viem'
import { mainnet } from 'viem/chains'
import { createEnsPublicClient } from '@ensdomains/ensjs'

const client = createEnsPublicClient({
  chain: mainnet,
  transport: http(),
})

const subgraphRecords = client.getSubgraphRecords({ name: 'ens.eth' })

const records = client.getRecords({
  name: 'ens.eth',
  records: {
    coins: [...(subgraphRecords?.coins || []), 'BTC', 'ETH', 'ETC', 'SOL'],
    texts: [
      ...(subgraphRecords?.texts || []),
      'avatar',
      'email',
      'description',
    ],
    contentHash: true,
    abi: true,
  },
})
address = ns.address('alice.eth')
var ensService = new Nethereum.ENS.ENSService(web3);
var address = await ensService.ResolveAddressAsync("alice.eth");

To learn what happens under the hood when you do a forward lookup, read the resolution section.

Multi-Chain Addresses (BTC, LTC, etc)
Multi-Chain

ENS Names aren't just limited to storing Ethereum Addresses, Names can be queried with any SLIP-0044 coin type, meaning you can also get addresses such as BTC, LTC. In addition to the above, Ethereum Chain specific addresses can also be queried using ENSIP-11.

The standardization of multichain addresses was first introduced in ENSIP-9, and also EIP-2304.

Multichain Address Lookup
import { useEnsMultichainAddress } from "ens-tools/react";

export const BitcoinAddress = () => {
    const { address: btcAddress, chainId } = useEnsMultichainAddress({
        name: "luc.eth",
        coinType: 0, // BTC
    });

    return <div>BTC: {btcAddress}</div>;
};
const ensName = await publicClient.getEnsAddress({
    name: normalize("wagmi-dev.eth"),
    coinType: 0, // BTC
});
const resolver = await provider.getResolver("luc.eth");
const btcAddress = await resolver?.getAddress(0);
Chain / NetworkID
BTC0
LTC2
DOGE3
Solana501
Optimism614
Polygon (Matic)966

... and many many more following SLIP-0044 and ENSIP-11

Decoding Address Hashes

Most libraries provide address decoding, however if you are reading these records raw values and would like to decode them to their multicoin appropriate address format, we recommend you read ENSIP-9, EIP-2304, and ENSIP-11.

Advanced

In-Depth ResolutionTo learn more about the resolution process, please read the Resolution section.Advanced
Contributors
Last Modified
3 days ago