Subdomains
Performing SQL queries on the ENS Unigraph requires that you have the unigraph plugin activated in your ENSNode instance. Learn more
Get a list of subdomains for the eth domain, including their Domain type (ENSv1Domain vs ENSv2Domain) — a single query spanning both protocol versions. See Connect for setup.
It is the name of an ENSDb Writer Schema, which is a database schema within an ENSDb instance, used to store indexed ENS data from a given ENSDb Writer instance. We use ensindexer_0 as the ENSDb Writer Schema Name in examples on this page, but your ENSDb Writer instance may be configured to use a different schema name. Make sure to replace
ensindexer_0 with the actual schema name used by your ENSDb Writer instance
when querying the ENSDb instance directly. For example, ENSIndexer allows configuring its own ENSDb Writer Schema Name with the ENSINDEXER_SCHEMA_NAME environment variable.
WITH parent AS ( SELECT subregistry_id FROM "ensindexer_0".domains WHERE canonical_name = 'eth' AND canonical = true)SELECT d.type, d.canonical_name, d.canonical_node, d.idFROM "ensindexer_0".domains dJOIN parent p ON d.registry_id = p.subregistry_idWHERE d.canonical = trueORDER BY d.canonical_nameLIMIT 5;| # | type | canonical_name | canonical_node | id |
|---|---|---|---|---|
| 1 | ENSv1Domain | [52602a50858115661619fb28cf543ee766c182e0be6743c72d5bd674b3d12686].eth | 0xe91ce3506cd47457c2b3f04c2736875ca1d17ed74bf1a328a7e64cca5ae8c94b | |
| 2 | ENSv1Domain | [d90db363b8bc1371f7d738d264ff7294bfc5636f907c467adf68321a3c6d8188].eth | 0x08c0f01c419a8971af6b3eefe2a8bba1556cccf1163df60b1cdbcab632c8ab48 | |
| 3 | ENSv2Domain | katrenpadu.eth | 0xf8ae81127bcd7ff99828b3dbd982a943d6dd961ee3f1a6ca707aa0eea913328e | |
| 4 | ENSv2Domain | roppp.eth | 0x39095c3dfb872d6441c95547f88591e7fb97014eef30cabe3df12a9b2a64dbe8 | |
| 5 | ENSv1Domain | sfmpfv44d0mig.eth | 0x9b365136312d7ee6e232e3c98e459bc8667ec818c47fbbc55bb5e23d0a21e8cc | |
Output matches a point in time snapshot of ENSDb result from our "V2 Sepolia" Hosted ENSNode instance. Live output depends on the configuration of your ENSNode instance and also changes that may have happened in ENS since this point in time snapshot example response was captured.
ensDb query builder and ensIndexerSchema
schema definition in the Connect example if you haven't already.
import { and, eq, inArray, asc } from "drizzle-orm";
const name = "eth";const limit = 5;
// Two-step:// 1) find parent domains// 2) query children by each parent domain's subregistryId.const parentDomains = await ensDb .select({ subregistryId: ensIndexerSchema.domain.subregistryId }) .from(ensIndexerSchema.domain) .where( and( eq(ensIndexerSchema.domain.canonicalName, name), eq(ensIndexerSchema.domain.canonical, true), ), );
if (parentDomains.length > 0) { const subdomains = await ensDb .select({ type: ensIndexerSchema.domain.type, canonicalName: ensIndexerSchema.domain.canonicalName, canonicalNode: ensIndexerSchema.domain.canonicalNode, id: ensIndexerSchema.domain.id, }) .from(ensIndexerSchema.domain) .where( and( inArray( ensIndexerSchema.domain.registryId, parentDomains.map((d) => d.subregistryId), ), eq(ensIndexerSchema.domain.canonical, true), ), ) .orderBy(asc(ensIndexerSchema.domain.__canonicalNamePrefix)) .limit(limit);
console.log(subdomains);}| # | type | canonicalName | canonicalNode | id |
|---|---|---|---|---|
| 1 | ENSv1Domain | [52602a50858115661619fb28cf543ee766c182e0be6743c72d5bd674b3d12686].eth | 0xe91ce3506cd47457c2b3f04c2736875ca1d17ed74bf1a328a7e64cca5ae8c94b | |
| 2 | ENSv1Domain | [d90db363b8bc1371f7d738d264ff7294bfc5636f907c467adf68321a3c6d8188].eth | 0x08c0f01c419a8971af6b3eefe2a8bba1556cccf1163df60b1cdbcab632c8ab48 | |
| 3 | ENSv2Domain | katrenpadu.eth | 0xf8ae81127bcd7ff99828b3dbd982a943d6dd961ee3f1a6ca707aa0eea913328e | |
| 4 | ENSv2Domain | roppp.eth | 0x39095c3dfb872d6441c95547f88591e7fb97014eef30cabe3df12a9b2a64dbe8 | |
| 5 | ENSv2Domain | sfmpfv44d0mig.eth | 0x9b365136312d7ee6e232e3c98e459bc8667ec818c47fbbc55bb5e23d0a21e8cc | |
Output matches a point in time snapshot of ENSDb result from our "V2 Sepolia" Hosted ENSNode instance. Live output depends on the configuration of your ENSNode instance and also changes that may have happened in ENS since this point in time snapshot example response was captured.