Subgraph
A GraphQL API that indexes blockchain events and data for efficient querying.
Last Updated
2026-03-29
Related Concepts
What is Subgraph?
A subgraph is a schema and set of rules that instructs an indexer to listen for specific blockchain events and organize them into a queryable database. It powers the GraphQL APIs that DApps use instead of scanning raw blockchain data.
How does Subgraph work?
- A developer defines which contract events to index and how to map them to entities like users, tokens, and transactions.
- The Graph's indexers run this code, monitoring the blockchain and updating a local database in real time.
- DApps query the subgraph's GraphQL endpoint to retrieve structured data instantly.
Why does Subgraph matter?
Without subgraphs, DApps would have to rescan the entire blockchain history for every query making them slow and expensive. Subgraphs do the indexing once and serve it to many applications efficiently.
Key features of Subgraph
- Event-driven indexing of specific contract activity
- Exposed via standard GraphQL APIs
- Decentralized indexing via The Graph network
- Real-time updates as new transactions are confirmed
Examples of Subgraph
Uniswap maintains subgraphs indexing all swaps, liquidity positions, and pool data. Aave's subgraph tracks lending, borrowing, and liquidation events.
OpenSea uses subgraphs to index NFT collection and trading data.
