The EventApi provides methods for querying historical events and subscribing to real-time event streams. Methods are in the sui and suix namespaces.
Event Queries
getEvents (sui namespace)
Returns events emitted by a specific transaction.
transaction_digest
TransactionDigest
required
The transaction digest
Array of events emitted by the transaction
curl -X POST https://fullnode.mainnet.sui.io:443 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getEvents",
"params": [
"7nPJKfZTx2YWqZWW3A8cXnFQVFQs7FKqBZqXU6qz5K4Q"
]
}'
queryEvents (suix namespace)
Returns a paginated list of events matching the specified filter.
The event query criteria. See Event Filters section below
Maximum number of items per page
Query result ordering (false = ascending, oldest first)
Paginated event results
Whether more results exist
curl -X POST https://fullnode.mainnet.sui.io:443 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "suix_queryEvents",
"params": [
{
"MoveEventType": "0x2::coin::CoinCreated<0x2::sui::SUI>"
},
null,
10,
false
]
}'
Event Subscriptions
subscribeEvent (WebSocket only)
Subscribes to a stream of Sui events matching the filter.
Event subscriptions are only available through WebSocket connections.
The filter criteria for the event stream
Stream of matching events
const WebSocket = require('ws');
const ws = new WebSocket('wss://fullnode.mainnet.sui.io:443');
ws.on('open', () => {
// Subscribe to all events
ws.send(JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'suix_subscribeEvent',
params: [{ All: [] }]
}));
});
ws.on('message', (data) => {
const event = JSON.parse(data);
console.log('Event:', event);
});
Event Filters
Event filters allow you to query specific types of events:
All Events
By Transaction Digest
{
"Transaction": "7nPJKfZTx2YWqZWW3A8cXnFQVFQs7FKqBZqXU6qz5K4Q"
}
By Move Event Type
{
"MoveEventType": "0x2::coin::CoinCreated<0x2::sui::SUI>"
}
By Move Module
{
"MoveModule": {
"package": "0x2",
"module": "coin"
}
}
By Sender Address
By Package
By Object
Time Range
{
"TimeRange": {
"start_time": "1234567890000",
"end_time": "1234567899999"
}
}
Combined Filters (AND)
{
"And": [
{ "Package": "0x2" },
{ "MoveModule": { "package": "0x2", "module": "coin" } }
]
}
Combined Filters (OR)
{
"Or": [
{ "Sender": "0x..." },
{ "Sender": "0x..." }
]
}
Event Structure
Each SuiEvent contains:
interface SuiEvent {
id: EventID; // Unique event identifier
packageId: ObjectID; // Package that emitted the event
transactionModule: string; // Module name
sender: SuiAddress; // Transaction sender
type: string; // Move event type
parsedJson: object; // Parsed event data
bcs: string; // BCS-encoded event data
timestampMs: string; // Event timestamp
}
Usage Examples
Rust SDK - Query Events
use sui_sdk::SuiClientBuilder;
use sui_json_rpc_types::EventFilter;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default()
.build("https://fullnode.mainnet.sui.io:443")
.await?;
// Query events by Move type
let events = sui.event_api()
.query_events(
EventFilter::MoveEventType(
"0x2::coin::CoinCreated<0x2::sui::SUI>".to_string()
),
None,
Some(10),
false
)
.await?;
for event in events.data {
println!("Event: {:?}", event.parsed_json);
}
Ok(())
}
Rust SDK - Subscribe to Events
use sui_sdk::SuiClientBuilder;
use sui_json_rpc_types::EventFilter;
use futures::StreamExt;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let sui = SuiClientBuilder::default()
.ws_url("wss://fullnode.mainnet.sui.io:443")
.build("https://fullnode.mainnet.sui.io:443")
.await?;
let mut subscribe_all = sui.event_api()
.subscribe_event(EventFilter::All(vec![]))
.await?;
while let Some(event) = subscribe_all.next().await {
match event {
Ok(e) => println!("Event: {:?}", e),
Err(err) => eprintln!("Error: {}", err),
}
}
Ok(())
}
TypeScript SDK - Subscribe to Events
import { SuiClient } from '@mysten/sui.js/client';
const client = new SuiClient({
url: 'https://fullnode.mainnet.sui.io:443',
});
// Subscribe to events
const unsubscribe = await client.subscribeEvent({
filter: { MoveEventType: '0x2::coin::CoinCreated<0x2::sui::SUI>' },
onMessage: (event) => {
console.log('Event:', event);
},
});
// Unsubscribe later
// unsubscribe();