suix_subscribeEvent - Sui
Example code for the suix_subscribeEvent JSON-RPC method. Complete guide on how to use suix_subscribeEvent JSON-RPC in GetBlock Web3 documentation.
This method subscribes to a stream of SUI events matching specified filter criteria via WebSocket. This enables real-time event monitoring for applications that need to react immediately to on-chain activities like DeFi trades, NFT mints, or smart contract state changes.
Parameters
filter
EventFilter
Yes
Event filter criteria
EventFilter Options
All- Match all eventsTransaction- Match by transaction digestMoveModule- Match by package and moduleMoveEventType- Match by event typeMoveEventModule- Match by event moduleMoveEventField- Match by field valueSender- Match by sender addressTimeRange- Match by timestamp range
Request Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://go.getblock.io/<ACCESS-TOKEN>/');
ws.on('open', () => {
const subscribeRequest = {
jsonrpc: '2.0',
id: 1,
method: 'suix_subscribeEvent',
params: [
{
MoveModule: {
package: '0x2',
module: 'coin'
}
}
]
};
ws.send(JSON.stringify(subscribeRequest));
});
ws.on('message', (data) => {
const response = JSON.parse(data);
console.log('Received:', response);
});Response Example
Response Parameters
subscription
number
Subscription ID
result
object
Event data when events arrive
Use Cases
Real-time DeFi price feeds
Live NFT activity monitoring
Transaction notifications
Smart contract event tracking
Building live dashboards
Error Handling
-32602
Invalid filter format
-32603
Internal error
Connection closed
WebSocket disconnected
SDK Integration
Last updated
Was this helpful?