# Using ENSNode with ENSjs

To use ENSNode with `@ensdomains/ensjs`, follow the [ENSjs documentation for custom subgraph URIs](https://github.com/ensdomains/ensjs/blob/17ab314/docs/basics/custom-subgraph-uris.md), replacing the subgraph URI with your ENSNode's subgraph-compatible api endpoint.

<IntegrateHostedEnsNodeTip />

```ts title="example.ts"
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

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](/docs/integrate/ens-subgraph/backwards-compatibility#unplanned-features)). The functions below are the patterns we see most often in the wild.

:::tip[Contributions]
If you'd like to highlight additional query patterns of the ENS Subgraph GraphQL, please [contribute to this documentation](https://github.com/namehash/ensnode/issues).
:::

### ENSjs Subgraph functions

- [`getDecodedName`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getDecodedName.ts) — 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`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getNameHistory.ts) — retrieves all events associated with a name.
- [`getNamesForAddress`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts) — 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`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts) — gets the records for a name from the subgraph; allows querying by a specific resolver id.
- [`getSubgraphRegistrant`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts) — gets the name registrant from the subgraph (`.eth` second-level domains only).
- [`getSubnames`](https://github.com/ensdomains/ensjs/blob/17ab314/packages/ensjs/src/functions/subgraph/getSubnames.ts) — gets the subnames for a name; supports `searchString`, filtering (by expiry, empty domains), ordering, and pagination.

### 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`](https://github.com/ensdomains/ens-app-v3/blob/328692ae832618f8143916c143b7e4cb9e520811/src/hooks/useResolverExists.ts#L27) — checks if a resolver exists.
- [`useRegistrationData`](https://github.com/ensdomains/ens-app-v3/blob/328692ae832618f8143916c143b7e4cb9e520811/src/hooks/useRegistrationData.ts#L31) — gets registration by id and `nameRegistered` events.

## ENSjs Documentation

Refer to the ENSjs documentation for further usage.

<LinkCard href="https://github.com/ensdomains/ensjs/" title="ENSjs Documentation" />