Events
Events are a way for applications to notify clients about state changes during transaction execution. They are emitted during message handling and can be queried and indexed by clients.Event System Overview
Event Structure
Events consist of a type and a list of attributes:types/events.go
Creating Events
types/events.go
Event Manager
The EventManager collects events during transaction execution:types/events.go
Accessing Event Manager
Typed Events
SDK supports typed events using Protocol Buffers:Emitting Typed Events
types/events.go
Usage Example
Core Event Service
The core API provides an event service for modules:core/event/service.go
Using Event Service
runtime/events.go
Module Events
Modules define standard events for their operations:x/bank/types/events.go
Event Emission Examples
Bank Module Transfer
Message Execution
Querying Events
Via RPC
Clients query events using CometBFT RPC:Event Query Syntax
Programmatic Querying
WebSocket Subscriptions
Subscribe to events in real-time:Event Indexing
CometBFT indexes events for querying:Best Practices
- Use typed events for consensus-critical events
- Emit events after state changes - don’t emit if operation fails
- Use consistent event types across modules
- Include relevant attributes for querying and filtering
- Document events in module specifications
- Use standard attributes (sdk.AttributeKeyModule, sdk.AttributeKeyAction, etc.)
- Don’t emit excessive events - they increase block size
- Emit deterministically - event order must be consistent across nodes
- Use EmitKV for non-consensus events (logs, metrics)
- Index selectively in production to manage storage
Standard Event Attributes
Common attributes used across modules:Event Format Example
Complete event from a bank transfer:Related Concepts
- Transactions - Transaction structure and execution
- Queries - Querying application state
- Messages - Message types and handlers