Domain Events
Performing SQL queries on the ENS Unigraph requires that you have the unigraph plugin activated in your ENSNode instance. Learn more
Fetch recent events for a Domain by its canonical name. This example joins the events, domain_events, and domains tables to retrieve domain events associated with the vitalik.eth name. See Connect for setup.
Canonical fields are populated on every Domain reachable from the canonical root, across both ENSv1 and ENSv2 — query them uniformly without branching by type. In SQL, these columns are canonical_name, canonical_path, canonical_node, and canonical_depth; in ensdb-sdk, the corresponding fields are canonicalName, canonicalPath, canonicalNode, and canonicalDepth.
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.
SELECT e.chain_id, e.block_number, e.transaction_hash, e.log_index, e.address as contract_address, e.sender, d.id as domain_idFROM "ensindexer_0".events eJOIN "ensindexer_0".domain_events de ON e.id = de.event_idJOIN "ensindexer_0".domains d ON de.domain_id = d.idWHERE d.canonical_name = 'vitalik.eth'AND d.canonical = trueORDER BY e.block_number DESC, e.log_index DESCLIMIT 5;| # | chain_id | block_number | transaction_hash | log_index | contract_address | sender | domain_id |
|---|---|---|---|---|---|---|---|
| 1 | 11155111 | 6023942 | 0x6206e95dc5ba5fc8d0804283498f17bac18081437b4198c824b62ee851622ba5 | 194 | 0xfed6a969aaa60e4961fcd3ebf1a2e8913ac65b72 | 0x225f137127d9067788314bc7fcc1f36746a3c3b5 | |
| 2 | 11155111 | 6023942 | 0x6206e95dc5ba5fc8d0804283498f17bac18081437b4198c824b62ee851622ba5 | 193 | 0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85 | 0x225f137127d9067788314bc7fcc1f36746a3c3b5 | |
| 3 | 11155111 | 4107392 | 0xf143118eb4100361f040b1ae5627562125f0cf1717073a8204befe5e512c80d4 | 22 | 0x0635513f179d50a207757e05759cbd106d7dfce8 | 0x179a862703a4adfb29896552df9e307980d19285 | |
| 4 | 11155111 | 4107386 | 0x6410de03e9a2f12543e491d1048209e5638d702948cf23d48a63d96a50efd20d | 19 | 0xfed6a969aaa60e4961fcd3ebf1a2e8913ac65b72 | 0x179a862703a4adfb29896552df9e307980d19285 | |
| 5 | 11155111 | 4107386 | 0x6410de03e9a2f12543e491d1048209e5638d702948cf23d48a63d96a50efd20d | 16 | 0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e | 0x179a862703a4adfb29896552df9e307980d19285 | |
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, desc, eq } from "drizzle-orm";
const name = "vitalik.eth";const limit = 5;
const domainEvents = await ensDb .select({ chainId: ensIndexerSchema.event.chainId, blockNumber: ensIndexerSchema.event.blockNumber, transactionHash: ensIndexerSchema.event.transactionHash, logIndex: ensIndexerSchema.event.logIndex, contractAddress: ensIndexerSchema.event.address, sender: ensIndexerSchema.event.sender, domainId: ensIndexerSchema.domain.id, }) .from(ensIndexerSchema.event) .innerJoin( ensIndexerSchema.domainEvent, eq(ensIndexerSchema.event.id, ensIndexerSchema.domainEvent.eventId), ) .innerJoin( ensIndexerSchema.domain, eq(ensIndexerSchema.domainEvent.domainId, ensIndexerSchema.domain.id), ) .where( and( eq(ensIndexerSchema.domain.canonicalName, name), eq(ensIndexerSchema.domain.canonical, true), ), ) .orderBy( desc(ensIndexerSchema.event.blockNumber), desc(ensIndexerSchema.event.logIndex), ) .limit(limit);
console.log(domainEvents);| # | chainId | blockNumber | transactionHash | logIndex | contractAddress | sender | domainId |
|---|---|---|---|---|---|---|---|
| 1 | 11155111 | 6023942 | 0x6206e95dc5ba5fc8d0804283498f17bac18081437b4198c824b62ee851622ba5 | 194 | 0xfed6a969aaa60e4961fcd3ebf1a2e8913ac65b72 | 0x225f137127d9067788314bc7fcc1f36746a3c3b5 | |
| 2 | 11155111 | 6023942 | 0x6206e95dc5ba5fc8d0804283498f17bac18081437b4198c824b62ee851622ba5 | 193 | 0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85 | 0x225f137127d9067788314bc7fcc1f36746a3c3b5 | |
| 3 | 11155111 | 4107392 | 0xf143118eb4100361f040b1ae5627562125f0cf1717073a8204befe5e512c80d4 | 22 | 0x0635513f179d50a207757e05759cbd106d7dfce8 | 0x179a862703a4adfb29896552df9e307980d19285 | |
| 4 | 11155111 | 4107386 | 0x6410de03e9a2f12543e491d1048209e5638d702948cf23d48a63d96a50efd20d | 19 | 0xfed6a969aaa60e4961fcd3ebf1a2e8913ac65b72 | 0x179a862703a4adfb29896552df9e307980d19285 | |
| 5 | 11155111 | 4107386 | 0x6410de03e9a2f12543e491d1048209e5638d702948cf23d48a63d96a50efd20d | 16 | 0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e | 0x179a862703a4adfb29896552df9e307980d19285 | |
Output matches a result snapshot; live output depends on your ENSNode instance.