ENS Logo
Docs

Listing a Users Names

In some cases you might want to show off all names that a user owns. Due to the nature of how the ENS Protocol works under the hood, this might be a slightly more difficult task than expected.

Fortunately, tooling has been developed to accommodate for this and to make it easier.

0x225...c3B5➡️
luc.eth
lucemans.eth
keukenrol.eth

Try it out using the widget below!

List Names

Why not all names?

Not all ENS names exist onchain (learn more about wildcard resolution), meaning we don't always know which names a user owns/controls.

The notable exception is second-level .eth names. Ownership of these names are onchain and indexable through scanning events on the appropriate smart contracts. Note that this does not necessarily mean address and text records associated with the name are onchain (read more about offchain resolvers).

Guidelines

When using one of the methods described below it is important to keep in mind that you should always allow for a user to manually enter a name, as not all names are indexable.

It is generally recommended to allow users to input a name using an input box and to verify it resolves to the correct address upon user-completion.

The Graph

The ENS subgraph indexes all events from relevant smart contracts and exposes them via a GraphQL endpoint. Note that addresses in filters must be lowercased.

ENSjs makes it easy to run common queries on the subgraph with strong type safety. Docs can be found here.

GraphQL
{
  domains(where: { owner: "0x225f137127d9067788314bc7fcc1f36746a3c3b5" }) {
    name
  }
  wrappedDomains(
    where: { owner: "0x225f137127d9067788314bc7fcc1f36746a3c3b5" }
  ) {
    name
  }
}

Airstack

Airstack is an API provider that includes a GraphQL endpoint to query all ENS names owned by a given address.

GraphQL
{
  Domains(
    input: {
      filter: { owner: { _eq: "0x179A862703a4adfb29896552DF9e307980D19285" } }
      blockchain: ethereum
    }
  ) {
    Domain {
      name
    }
  }
}

Alchemy

Alchemy has several API endpoints for fetching NFTs, which we can use to query a list of names owned by a given address.

Alchemy
// 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)

const walletAddress = '0x458d1E307CcA61C0Bea82f7663F66831175EcDe8' // replace with wallet address
const ensContractAddress = '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'
const nfts = await alchemy.nft.getNftsForOwner(walletAddress, {
  contractAddresses: [ensContractAddress],
})

console.log(nfts)
Contributors
Last Modified
10 days ago