Try it Live
Run EventLog examples in the interactive playground
Sort Order
Primary: Block Number
Logs sorted by block number ascending (earliest blocks first):Secondary: Log Index
Within same block, sorted by log index ascending:Missing Values
Logs withoutblockNumber or logIndex treated as 0:
Usage Patterns
Chronological Processing
Combining with Filtering
Finding Latest Log
Finding Earliest Log
Grouping by Block
Time-Ordered Event Replay
Detecting Missing Logs
Pagination
Implementation
Sort algorithm:- Compare block numbers (ascending)
- If equal, compare log indices (ascending)
- Treat undefined as 0
Performance
- Time complexity: O(n log n)
- Space complexity: O(n) (creates new array)
- Stable sort: Maintains relative order of equal elements
See Also
- filterLogs - Filter before sorting
- isRemoved - Filter removed logs
- Fundamentals - Log ordering and blocks

