Skip to content

Using ENSNode with ENSjs

To use ENSNode with @ensdomains/ensjs, follow the ENSjs documentation for custom subgraph URIs, replacing the subgraph URI with your ENSNode’s subgraph-compatible api endpoint.

import { http, createClient } from "viem";
import { mainnet } from "viem/chains";
import { addEnsContracts } from "@ensdomains/ensjs";
import { getNamesForAddress } from "@ensdomains/ensjs/subgraph";
const mainnetWithEns = addEnsContracts(mainnet);
const chain = {
...mainnetWithEns,
subgraphs: {
ens: {
// use the NameHash-hosted 'alpha' instance subgraph-compatible responses with (mainnet, Base, and Linea) names
url: "https://api.alpha.ensnode.io/subgraph",
// or use your own local instance
// url: 'http://localhost:42069/subgraph',
},
},
};
const client = createClient({
chain,
transport: http(),
});
const names = await getNamesForAddress(client, {
address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // vitalik.eth
});

Once ENSjs is pointed at an ENSNode Subgraph-compatible endpoint, its Subgraph functions work unchanged. ENSNode’s Subgraph-compatible GraphQL API provides full compatibility with these use cases (and all other possible queries, with the only exception of the unplanned features). The functions below are the patterns we see most often in the wild.

  • getDecodedName — gets the full name for a name with unknown labels from the subgraph (heals encoded labels, splits the name into labels, finds domains by id, and queries the domain by namehash).
  • getNameHistory — retrieves all events associated with a name.
  • getNamesForAddress — gets all names related to an address via registrant, owner, wrappedOwner, and resolvedAddress; supports searchString, filtering (by expiry, reverse records, empty domains), ordering (by expiry date, name, labelName, createdAt), and pagination.
  • getSubgraphRecords — gets the records for a name from the subgraph; allows querying by a specific resolver id.
  • getSubgraphRegistrant — gets the name registrant from the subgraph (.eth second-level domains only).
  • getSubnames — gets the subnames for a name; supports searchString, filtering (by expiry, empty domains), ordering, and pagination.

These query patterns come from the ENSv1 Manager App (ens-app-v3). They may not go through ENSjs directly, but they’re useful references for the kinds of Subgraph queries real apps depend on:

Refer to the ENSjs documentation for further usage.