Previous Module
Contract Upgrade Proxy

🗃️ GraphQL Indexer: The Graph Protocol

Learn how to query blockchain data faster than RPC

🔍 The Blockchain Data Problem

Blockchain nodes are terrible databases. Want to find all NFT transfers for a wallet? You need to scan millions of blocks, parse every transaction, filter events, and aggregate results. A simple query takes minutes and hammers your RPC endpoint. Etherscan, Uniswap, OpenSea—they don't query nodes directly. They use indexers: systems that watch the blockchain, extract data, organize it in a real database, and serve it via GraphQL. The Graph is the decentralized indexing protocol that powers most dApps.

🎮 Interactive: RPC vs Indexer Performance

Compare query performance between direct RPC calls and an indexed GraphQL endpoint. Select a data source and run a query to fetch "All Uniswap swaps for wallet 0x1234... in the last 30 days".

Query
// Pseudocode - actual complexity much worse
for (block = latestBlock; block > latestBlock - 216000; block--) {
  logs = eth_getLogs(block, uniswapV3Pool)
  for (log in logs) {
    if (log.topics[1] === wallet) {
      swaps.push(parseSwap(log))
    }
  }
}

💡 Why Indexers Are Essential

1.
Speed: Pre-processed data = instant queries. RPC takes 4.5s for what indexer does in 150ms (30x faster).
2.
Complex Queries: "Show me all NFTs owned by wallet X with floor price > 1 ETH" is trivial for indexer, impossible for RPC.
3.
Cost: One RPC query scans 216,000 blocks = thousands of requests. One GraphQL query = single request. Save 99% on API costs.
4.
User Experience: Users won't wait 5 seconds for data. Indexers enable real-time dashboards, instant search, live charts.

🌐 The Graph Protocol

The Graph is the decentralized indexing layer for Web3. Think "Google for blockchains"—instead of centralized servers, indexers run on a decentralized network. Developers deploy subgraphs (indexing rules), indexers process them, and dApps query via GraphQL.

1. Deploy Subgraph
Define what data to index (contracts, events, entities)
2. Indexers Process
Network nodes watch blockchain, extract data, build database
3. dApps Query
GraphQL endpoint serves data instantly (no blockchain calls)

🎯 Real-World Usage

Uniswap: All swap history, liquidity data, volume charts—powered by The Graph subgraph.
Aave: Lending positions, borrow rates, liquidation history—indexed for instant access.
ENS: Domain registrations, transfers, expiry tracking—all via subgraph queries.
Your dApp: Any contract data you need—transfers, balances, events, state changes—can be indexed.