Skip to content

ENSDb SQL

This page provides an overview of the ENSDb SQL interface and how to use it in your applications.

Connect to an ENSDb instance (a PostgreSQL database). The examples below assume you that ENSDb instances are served from a PostgreSQL server at host:5432 with databases named ensdb_mainnet, ensdb_testnet, and ensdb_devnet:

Terminal window
# 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 environment
psql postgresql://user:password@host:5432/ensdb_devnet

Once connected to an ENSDb instance, discover its ENSIndexer Schemas:

SELECT DISTINCT ens_indexer_schema_name
FROM ensnode.metadata;

Query data from your ENSDb instance:

-- Get ENSv1 domains from the ENSIndexer Schema with the `ensindexer_mainnet` ENSIndexer Schema Name
SELECT * FROM ensindexer_mainnet.domains
WHERE type = 'ENSv1Domain'
LIMIT 10;
-- Get ENSv2 domains from the ENSIndexer Schema with the `ensindexer_mainnet` ENSIndexer Schema Name
SELECT * FROM ensindexer_mainnet.domains
WHERE type = 'ENSv2Domain'
LIMIT 10;
-- Get indexing status snapshot for the ENSNode Schema with the `ensindexer_mainnet` ENSIndexer Schema Name
SELECT value -> 'indexingStatus' FROM "ensnode"."metadata"
WHERE ens_indexer_schema_name = 'ensindexer_mainnet'
AND key = 'indexing_metadata_context'
AND value -> 'indexingStatus' -> 'omnichainSnapshot' ->> 'omnichainStatus' = 'omnichain-backfill';