This cookbook provides ready-to-use query patterns for common DeFi analytics tasks. All examples use BlockDB’s canonical datasets and can be adapted to your specific use cases.
All queries use the _tracing_id field for lineage tracking. Use this field to verify data provenance and join across datasets.
Calculate total transaction volume for a specific token:
Copy
SELECT t.to_address, SUM(CAST(t.effective_gas_price_wei AS NUMERIC) * t.gas_used) / 1e18 as total_eth_volume, COUNT(*) as tx_countFROM blockdb0102_transactions_v1 tWHERE t.chain_id = 1 AND t.to_address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' -- USDC AND t.block_time >= '2025-01-01T00:00:00Z' AND t.status_success = trueGROUP BY t.to_address;
SELECT b._tracing_id as block_tracing_id, t._tracing_id as tx_tracing_id, l._tracing_id as log_tracing_id, b.block_number, t.tx_hash, l.contract_addressFROM blockdb0101_blocks_v1 bINNER JOIN blockdb0102_transactions_v1 t ON b.chain_id = t.chain_id AND b.block_number = t.block_numberINNER JOIN blockdb0103_logs_v1 l ON t.chain_id = l.chain_id AND t.tx_hash = l.tx_hashWHERE b.chain_id = 1 AND b.block_number = 12345678ORDER BY l.log_index;