The Graph API

Index and query blockchain data with The Graph protocol. Use GraphQL to fetch DeFi, NFT, and protocol data efficiently.

What is The Graph?

The Graph is a decentralized indexing protocol for querying blockchain data. Instead of scanning entire blockchains, developers use subgraphs to efficiently query specific data like token balances, swap transactions, or NFT ownership.

Popular Subgraphs

  • Uniswap - DEX trading data, pools, tokens
  • Aave - Lending/borrowing data
  • ENS - Domain name data
  • OpenSea - NFT trading data
  • Compound - Lending protocol metrics

Querying The Graph

# GraphQL query example
{
  tokens(first: 5, orderBy: totalValueLockedUSD, orderDirection: desc) {
    id
    symbol
    name
    totalValueLockedUSD
    volumeUSD
  }
}

# Endpoint: https://gateway.thegraph.com/api/[api-key]/subgraphs/id/[subgraph-id]

The Graph vs Direct RPC

  • The Graph - Pre-indexed data, GraphQL, pay per query
  • Direct RPC - Raw data, JSON-RPC, pay per request
  • Use both - RPC for writes, Graph for reads

Pricing

Free Tier

30K-100K free queries/month through The Graph's hosted service.

API Keys

Pay for what you use with API keys from The Graph Foundation.

Alternatives

  • Covalent - Unified API for multiple chains
  • Bitquery - GraphQL for 30+ blockchains
  • Dune Analytics - SQL-based blockchain analytics

Start Using The Graph

Get API Key DeFi API Guide