Links

Working with ENS

Before you can begin interacting with ENS, you will need to obtain a reference to the ENS registry. How you do this depends on the library you are using.
The Javascript libraries (ethers.js, viem, wagmi, ensjs, and web3.js) can be used in any environment. If you're building a React app, we recommend wagmi.
ethers.js
viem
ensjs
web3.js
go-ens
web3.py
web3j
import { providers } from 'ethers'
const provider = new providers.JsonRpcProvider('RPC_URL_HERE');
// ENS functionality is provided directly on the core provider object.
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createPublicClient({ chain: mainnet, transport: http() });
// ENS functionality is provided directly on the core client
import { ENS } from '@ensdomains/ensjs'
import { providers } from 'ethers'
const ens = new ENS();
const provider = new providers.JsonRpcProvider('RPC_URL_HERE');
await ens.setProvider(provider);
import { Web3 } from 'web3'
const web3 = new Web3('RPC_URL_HERE');
const ens = web3.eth.ens;
import (
ens "github.com/wealdtech/go-ens/v2"
ethereum "github.com/ethereum/go-ethereum"
)
// Can dial up a connection through either IPC or HTTP/HTTPS
client, err := ethereum.Dial("/home/ethereum/.ethereum/geth.ipc")
registry, err := ens.Registry(client)
from ens.auto import ns
EnsResolver ens = new EnsResolver(web3j, 300 /* sync threshold, seconds */);
Some web3 libraries - e.g., ethers.js, viem, web3j, and web3.py - have integrated support for name resolution. In these libraries, you can pass in an ENS name anywhere you can supply an address, meaning you do not need to interact directly with their ENS APIs unless you want to manually resolve names or do other ENS operations.
If no library is available for your platform, you can instantiate the ENS registry contract directly using the interface definition here. Addresses for the ENS registry on each supported network are available in the ENS Deployments page.

React hooks for ENS

wagmi is a collection of React Hooks containing everything you need to start working with Ethereum, including ENS.
To get access to wagmi's ENS hooks, wrap your project in a WagmiConfig provider:
import { WagmiConfig, configureChains, createConfig } from 'wagmi'
import { goerli, mainnet } from 'wagmi/chains'
import { publicProvider } from 'wagmi/providers/public'
const chains = [mainnet, goerli]
const { publicClient } = configureChains(chains, [publicProvider()])
const wagmiConfig = createConfig({
publicClient,
})
export default function App() {
return (
<WagmiConfig config={wagmiConfig}>
{/* Your app here */}
</WagmiConfig>
)
}