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.
You don't need to run your own ENSNode to follow this guide — the steps below default to a NameHash-hosted instance. Browse the available deployments below.
Our hosted ENSNode instances currently run ENSNode v1.13. If you are querying them from your own app, you must use
enssdk@1.13.1 (and enskit@1.13.1 when using React). The latest published versions (1.14.0+) contain breaking changes in the Omnigraph API data model not yet deployed to our hosted infrastructure. Use these exact install commands:
npm install enssdk@1.13.1 # or, for React apps: npm install enskit@1.13.1 enssdk@1.13.1This notice will be removed once the hosted instances are upgraded.
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.