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 = 'wrapnation.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 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 42 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | 0x801d2e48d378f161dba7ad7ad002ad557714c191 | |
| 2 | 11155111 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 38 | 0x64c81210d0e580cfc7746f3fb910bf0e8f6378e1 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | |
| 3 | 11155111 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 37 | 0x64c81210d0e580cfc7746f3fb910bf0e8f6378e1 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | |
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, desc, eq } from "drizzle-orm";
const name = "wrapnation.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 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 42 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | 0x801d2e48d378f161dba7ad7ad002ad557714c191 | |
| 2 | 11155111 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 38 | 0x64c81210d0e580cfc7746f3fb910bf0e8f6378e1 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | |
| 3 | 11155111 | 10918673 | 0xca5e111932f0b26e1d458c690c5dfe8b2b8165ee2a937c04e4021e93a71954e4 | 37 | 0x64c81210d0e580cfc7746f3fb910bf0e8f6378e1 | 0xb68e594a47fe057bd31e7a8229ffcfd85b2e28af | |
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.