Resolve with ENS
A handles.link name resolves like any other ENS name. Your library needs to
support wildcard names (ENSIP-10) and
offchain lookups (ERC-3668). viem
and ethers v6 support both.
Check which chains the gateways serve under Which chains are served.
With viem
Section titled “With viem”ENS lives on Ethereum mainnet, so connect to mainnet. Pass the chain you want an address for as a coin type:
import { createPublicClient, http, toCoinType } from 'viem';import { mainnet } from 'viem/chains';
const client = createPublicClient({ chain: mainnet, transport: http() });
const address = await client.getEnsAddress({ name: 'octocat.github.handles.link', coinType: toCoinType(mainnet.id),});address is the holder of octocat on GitHub, as recorded on Ethereum
mainnet. It is null if nobody holds the handle there.
toCoinType(1) is 60, the coin type ENS uses for Ethereum, so leaving out
coinType gives the same answer.
Testnets
Section titled “Testnets”Testnet names live in ENS on Sepolia, so connect to Sepolia:
import { createPublicClient, http, toCoinType } from 'viem';import { sepolia } from 'viem/chains';
const client = createPublicClient({ chain: sepolia, transport: http() });
const onSepolia = await client.getEnsAddress({ name: 'testyakly.github.testnet.handles.link', coinType: toCoinType(sepolia.id),});
const onEden = await client.getEnsAddress({ name: 'testyakly.github.testnet.handles.link', coinType: 3735928814n,});Both give 0xb2c7c8ea84932a0dadf8f6f0550cfc89a345540c, which holds
testyakly on both chains. toCoinType(3735928814) throws, so the Eden
coin type is written out; see Testnets.
In a wallet
Section titled “In a wallet”Paste the name into the recipient field. Wallets that support ENS subnames with offchain lookups, such as MetaMask, resolve it the same way.
Compared to IdentityRegistry
Section titled “Compared to IdentityRegistry”ENS answers from the gateway’s copy of IdentityRegistry, which can be a few
blocks behind, and a signed answer stays valid for 5 minutes. So right after
a handle changes holder, ENS can still give the old one. Which one to use
depends on where the name comes from:
- Use ENS when a person types or pastes a name, or when you want names to work in wallets you do not control.
- Use
IdentityRegistryfrom your own code and contracts. It needs no gateway, and it can also tell you when the handle was proved. See Resolve a handle.