ENSDb SDK
This page provides an overview of the ENSDb SDK and how to use it in your applications.
For TypeScript projects, the ENSDb SDK provides a convenient and efficient way to interact with your ENSDb instance.
Installation
Section titled “Installation”You can install the @ensnode/ensdb-sdk package from the NPM registry, using your preferred package manager:
npm install @ensnode/ensdb-sdkpnpm install @ensnode/ensdb-sdkyarn add @ensnode/ensdb-sdkExample Usage
Section titled “Example Usage”Canonical fields (canonicalName, canonicalPath, canonicalNode, canonicalDepth) are
populated on every Domain reachable from the canonical root, across both ENSv1 and ENSv2—query
them uniformly without branching by type.
import { EnsDbReader, IndexingMetadataContextStatusCodes } from "@ensnode/ensdb-sdk";import { count, eq } from "drizzle-orm";
// Connect to a specific ENSDb instance by providing its connection string and// the ENSIndexer Schema Name you want to queryconst ensDbReader = new EnsDbReader(ensDbConnectionString, ensIndexerSchemaName);const { ensDb, ensIndexerSchema } = ensDbReader;
// Fetch a Domain by its canonical nameconst [vitalik] = await ensDb .select() .from(ensIndexerSchema.domain) .where(eq(ensIndexerSchema.domain.canonicalName, "vitalik.eth"));
// Count an address's Domains, grouped by Domain type (ENSv1 vs ENSv2)const counts = await ensDb .select({ type: ensIndexerSchema.domain.type, count: count() }) .from(ensIndexerSchema.domain) .where(eq(ensIndexerSchema.domain.ownerId, "0xd8da6bf26964af9d7eed9e03e53415d37aa96045")) .groupBy(ensIndexerSchema.domain.type);
// Get indexing status snapshotconst indexingMetadataContext = await ensDbReader.getIndexingMetadataContext();if (indexingMetadataContext.statusCode === IndexingMetadataContextStatusCodes.Initialized) { const indexingStatusSnapshot = indexingMetadataContext.indexingStatus; // Do something with the indexing status snapshot}