ENS Logo
Docs

Address Lookup

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. Any blockchain address (BTC, LTC, SOL, etc.) can be queried by SLIP-0044 coin type or a value derived from an EVM Chain ID (specified in ENSIP-11). This includes Ethereum L2 networks such as OP Mainnet and Base.

For EVM Chains, always use its ENSIP-11 coin type, irrespective of being included in SLIP-0044 (like Ether Classic).

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);
NetworkCoin Type
Bitcoin0
Litecoin2
Dogecoin3
Ethereum60
Solana501
OP Mainnet2147483658
Polygon2147483785
Base2147492101
Arbitrum One2147525809

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

Decoding Address Hashes

ENS resolvers store all addresses in bytes, which may have to be encoded to their respective address formats. To do this, we recommend using the @ensdomains/address-encoder package.

Advanced

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