Unigraph SQL Examples
These examples show the same queries two ways: in raw SQL (any PostgreSQL client, any language) and with the typed @ensnode/ensdb-sdk for TypeScript projects.
SQL access requires connecting to your own self-hosted ENSDb instance.
Connect
Section titled “Connect”The Unigraph lives in ENSDb, a PostgreSQL database. Each ENSIndexer instance writes to its own ENSIndexer Schema (e.g. ensindexer_0); shared operational metadata lives in the ensnode schema.
# Production environment (mainnet data)psql postgresql://user:password@host:5432/ensdb_mainnet
# Pre-production environment (testnet data)psql postgresql://user:password@host:5432/ensdb_testnet
# Staging / local development environmentpsql postgresql://user:password@host:5432/ensdb_devnetDiscover the available ENSIndexer Schemas:
SELECT DISTINCT ens_indexer_schema_nameFROM ensnode.metadata;npm install @ensnode/ensdb-sdkimport { EnsDbReader } from '@ensnode/ensdb-sdk';
// Connect by providing a connection string and the ENSIndexer Schema Name to queryconst ensDbReader = new EnsDbReader(ensDbConnectionString, ensIndexerSchemaName);const { ensDb, ensIndexerSchema } = ensDbReader;Canonical fields (canonical_name, canonical_path, canonical_node, canonical_depth) are populated on every Domain reachable from the canonical root, across both ENSv1 and ENSv2 — query them uniformly without branching by type.