Generates conversions from a struct into a published event. Fields of the struct become topics and data parameters in the published event. Includes the event in the contract spec so that clients can generate bindings for the type and downstream systems can understand the meaning of the event.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/stellar/rs-soroban-sdk/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
Parameters
Optional custom list of fixed topic strings. If not specified, the event name in snake_case is used as the single fixed topic.
Format for the event data. Options:
"map"(default): Data is stored as aMapwith field names as keys"vec": Data is stored as aVecof values in field order"single-value": Data is the value of a single field (must have exactly one data field)
Event Structure
Events consist of:- Fixed topics: Static strings defined by the
topicsparameter or derived from the event name - Dynamic topics: Values from fields marked with
#[topic] - Data: Values from fields not marked with
#[topic], formatted according todata_format
Field Attributes
#[topic]
Mark a field as a topic. Topic fields are indexed and can be efficiently filtered by downstream systems.
Examples
Basic Event
The event will have a single fixed topic matching the name of the struct in lower snake case. The fixed topic will appear before any topics listed as fields.- Topics:
["my_event", <value of my_topic>] - Data (as Map):
{my_event_data: <u32>, more_event_data: <u64>}
Event with Custom Topics
Define a contract event with a custom list of fixed topics.- Topics:
["my_contract", "an_event", <value of my_topic>] - Data (as Map):
{my_event_data: <u32>, more_event_data: <u64>}
Event with Vec Data Format
- Topics:
["my_event", <value of my_topic>] - Data (as Vec):
[<my_event_data: u32>, <more_event_data: u64>]
Event with Single Value Data Format
When the data format is a single value there must be no more than one data field.- Topics:
["my_event", <value of my_topic>] - Data:
<my_event_data: u32>
Full Example with Contract
Defining an event, publishing it in a contract, and testing it.See Also
Env- Access the events interface via env.events()#[contracttype]- Define general contract types- Events Module - Events API documentation