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.

This method requires a WebSocket connection, not HTTP.

Parameters

Parameter
Type
Required
Description

filter

EventFilter

Yes

Event filter criteria

EventFilter Options

  • All - Match all events

  • Transaction - Match by transaction digest

  • MoveModule - Match by package and module

  • MoveEventType - Match by event type

  • MoveEventModule - Match by event module

  • MoveEventField - Match by field value

  • Sender - Match by sender address

  • TimeRange - Match by timestamp range

Request Example

subscribe.js
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

Parameter
Type
Description

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

Error Code
Description

-32602

Invalid filter format

-32603

Internal error

Connection closed

WebSocket disconnected

SDK Integration

Last updated

Was this helpful?