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 | $2442.eth | 0x89c28481de9640822dd25f821e341b0304640b9363d419e10b9d6b99f049fc8c | |
| 2 | ENSv1Domain | $bless.eth | 0xfca869315283e0747c929ff17f57d6712cf76b372395eef8b770595d393902ea | |
| 3 | ENSv1Domain | $pauly.eth | 0x8254e524ac45f21ce3a3483e52dbedf1aa7bc5d5cff69d4a189df5e369f6eacf | |
| 4 | ENSv1Domain | $vince.eth | 0x1630be8a50ed7d79c1a5510ca7aaf3d6a483596affcc81c2dbaad17262619dcc | |
| 5 | ENSv1Domain | 0000000000000000000000000000000000000000.eth | 0xc13733debbac0dd0143dddcbfe8fcede7c3405033357f034d8b0779ad85802e1 | |
Output matches a result snapshot; live output depends on your ENSNode instance.
ensDb query builder and ensIndexerSchema
schema definition in the Connect example if you haven't already.
import { and, eq, asc } from "drizzle-orm";
const name = "eth";const limit = 5;
// Two-step:// 1) find parent domain,// 2) query children by parent domain's subregistryId.const [parentDomain] = await ensDb .select({ subregistryId: ensIndexerSchema.domain.subregistryId }) .from(ensIndexerSchema.domain) .where( and( eq(ensIndexerSchema.domain.canonicalName, name), eq(ensIndexerSchema.domain.canonical, true), ));
if (parentDomain?.subregistryId) { 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( eq(ensIndexerSchema.domain.registryId, parentDomain.subregistryId), eq(ensIndexerSchema.domain.canonical, true), ) ) .orderBy(asc(ensIndexerSchema.domain.canonicalName)) .limit(limit);
console.log(subdomains);}| # | type | canonicalName | canonicalNode | id |
|---|---|---|---|---|
| 1 | ENSv1Domain | $2442.eth | 0x89c28481de9640822dd25f821e341b0304640b9363d419e10b9d6b99f049fc8c | |
| 2 | ENSv1Domain | $bless.eth | 0xfca869315283e0747c929ff17f57d6712cf76b372395eef8b770595d393902ea | |
| 3 | ENSv1Domain | $pauly.eth | 0x8254e524ac45f21ce3a3483e52dbedf1aa7bc5d5cff69d4a189df5e369f6eacf | |
| 4 | ENSv1Domain | $vince.eth | 0x1630be8a50ed7d79c1a5510ca7aaf3d6a483596affcc81c2dbaad17262619dcc | |
| 5 | ENSv1Domain | 0000000000000000000000000000000000000000.eth | 0xc13733debbac0dd0143dddcbfe8fcede7c3405033357f034d8b0779ad85802e1 | |
Output matches a result snapshot; live output depends on your ENSNode instance.