💼 Real-World Patterns: Uniswap & Aave
Discover how production dApps use The Graph
Query blockchain data efficiently with The Graph
Your Progress
0 / 5 completed🚀 Production Indexing Patterns
Real dApps need more than basic indexing. Aggregations track totals (daily volume, TVL). Time-series data enables charts (price history, growth). Relationships connect entities (user → positions → tokens). Subscriptions push live updates (new swaps, transfers). These patterns power Uniswap dashboards, Aave analytics, OpenSea collections, and every major DeFi protocol. Master them to build production-grade dApps.
🎮 Interactive: Pattern Explorer
Explore common indexing patterns used in production dApps. Select a pattern to see schema definition, mapping code, and real-world examples.
Aggregation Entities
Track cumulative stats (totals, counts, averages) by creating aggregate entities updated on every event
Token total supply, user transaction count, protocol TVL, daily volume
// Schema
type DailyVolume @entity {
id: ID! # Format: "YYYY-MM-DD"
date: String!
volumeUSD: BigDecimal!
txCount: Int!
}
// Mapping
export function handleSwap(event: SwapEvent): void {
let dayId = event.block.timestamp.toI32() / 86400
let id = dayId.toString()
let daily = DailyVolume.load(id)
if (!daily) {
daily = new DailyVolume(id)
daily.date = new Date(dayId * 86400 * 1000).toISOString()
daily.volumeUSD = BigDecimal.fromString("0")
daily.txCount = 0
}
daily.volumeUSD = daily.volumeUSD.plus(event.params.amountUSD)
daily.txCount = daily.txCount + 1
daily.save()
}Uniswap tracks daily volume, Aave tracks total deposited, compound tracks supply rates over time
🏗️ Architecture Best Practices
⚙️ Performance Optimization
🎯 Production Checklist
entity.load() safely.