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.
1.13.1. The Omnigraph GraphQL schema is bundled inside the SDK and consumed by the gql.tada TypeScript plugin to type your queries, so pin an exact version (no ^ or ~) of enssdk@1.13.1 (and enskit@1.13.1 when using
React) to keep your generated types matched to the deployed schema. Use these exact install commands:
npm install enssdk@1.13.1 # or, for React apps: npm install enskit@1.13.1 enssdk@1.13.1
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});Well-Known Subgraph Queries
Section titled “Well-Known Subgraph Queries”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.
If you’d like to highlight additional query patterns of the ENS Subgraph GraphQL, please contribute to this documentation.
ENSjs Subgraph functions
Section titled “ENSjs Subgraph functions”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; supportssearchString, 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 (.ethsecond-level domains only).getSubnames— gets the subnames for a name; supportssearchString, filtering (by expiry, empty domains), ordering, and pagination.
ENSv1 Manager App queries
Section titled “ENSv1 Manager App queries”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:
useResolverExists— checks if a resolver exists.useRegistrationData— gets registration by id andnameRegisteredevents.
ENSjs Documentation
Section titled “ENSjs Documentation”Refer to the ENSjs documentation for further usage.