How Cedra Indexing Works
Understand the complete journey from blockchain transactions to queryable data in your applications.
🔄 The Indexing Pipeline
📦 What's in a Transaction?
Every transaction your indexer receives contains:
Events - What happened during execution
// Example: Token Transfer Event
Event {
account_address: "0x123...",
type: "0x1::coin::TransferEvent",
data: {
from: "0xabc...",
to: "0xdef...",
amount: 1000000
}
}
Events are perfect for:
- ✅ Activity feeds
- ✅ Transaction history
- ✅ User analytics
State Changes - How storage was modified
// Example: Balance Update
WriteSet {
resource: "0x1::coin::CoinStore",
address: "0x456...",
data: {
coin: { value: 5000000 },
frozen: false
}
}
State changes are essential for:
- ✅ Current balances
- ✅ Ownership tracking
- ✅ Protocol state
Metadata - Transaction details
// Transaction context
Transaction {
version: 1234567, // Unique sequence number
hash: "0xabc123...", // Transaction identifier
timestamp: 1704067200, // When it happened
success: true, // Execution status
gas_used: 1500 // Computational cost
}
🎯 Processing Flow
Step 1: Connect to Stream
Your processor connects to Cedra's Transaction Stream Service:
# No authentication needed - it's public!
transaction_stream:
endpoint: https://testnet.cedra.dev
batch_size: 1000 # Process 1000 txns at once
Step 2: Extract Data
Choose what to index based on your needs:
Strategy | Use When | Example |
---|---|---|
Events Only | Tracking actions | DEX swaps, transfers |
State Only | Current values | Token balances, TVL |
Hybrid | Complete picture | Full protocol state |
Step 3: Transform & Store
Process data and save to PostgreSQL:
// Simplified processing logic
async fn process(transactions: Vec<Transaction>) {
for txn in transactions {
// Extract relevant events
let events = txn.events
.filter(|e| e.type.contains("YourContract"));
// Transform to your schema
let records = events.map(|e| transform(e));
// Batch insert to database
database.insert_batch(records).await;
}
}
Step 4: Query via GraphQL
Your data is instantly available:
query YourCustomData {
your_table(
where: {timestamp: {_gte: "2024-01-01"}}
order_by: {value: desc}
) {
id
timestamp
value
metadata
}
}
⚡ Key Features
🔄 Real-time Processing
- Transactions indexed within seconds
- Live data feeds for dashboards
- WebSocket subscriptions available
🛡️ Reliability Built-in
- Version Tracking: Sequential processing guaranteed
- Automatic Recovery: Resume from last checkpoint
- No Data Loss: Every transaction processed exactly once
📈 Scalable Architecture
- Process millions of transactions
- Parallel processing support
- Optimized batch operations
🎬 See It In Action
Example: Indexing Token Transfers
- Transaction occurs on Cedra blockchain
- Stream delivers to your processor (< 1 second)
- Processor extracts transfer events
- Data stored in PostgreSQL
- GraphQL serves to your application
Total time: ~2-3 seconds from transaction to queryable data!
📊 Version System
Cedra uses a sequential version system that ensures data consistency:
Transaction Version Timeline:
[1] → [2] → [3] → [4] → [5] → ...
↑
Your indexer processes each version exactly once
Benefits:
- ✅ No gaps: Every transaction captured
- ✅ Ordered: Process in exact sequence
- ✅ Resumable: Restart from any version
- ✅ Verifiable: Check processing completeness
🚦 Processing Status
Monitor your indexer's progress:
-- Check current processing status
SELECT * FROM processor_status;
┌─────────────┬────────────────────┬─────────────────┐
│ processor │ last_success_version │ last_updated │
├─────────────┼────────────────────┼─────────────────┤
│ my_indexer │ 1234567 │ 2024-01-15 10:30 │
└─────────────┴────────────────────┴─────────────────┘
🔍 What Happens During a Restart?
The indexer automatically handles failures:
No manual intervention needed - just restart and continue!
💡 Best Practices
- Batch Operations: Process 1000-5000 transactions per batch
- Index Strategy: Create database indexes on frequently queried fields
- Monitor Lag: Keep processing within 100 versions of chain tip
- Don't process transactions one-by-one (too slow)
- Don't skip version tracking (loses recovery ability)
- Don't ignore failed transactions (may contain important reverts)
🎯 Next Steps
Now that you understand how indexing works:
- SDK Guide - Get started with processors
- Processors - Available processor types
- Common Queries - GraphQL patterns
You now understand the complete indexing flow. Time to understand queries!