Sui.

Post

Share your knowledge.

harry phan.
Jul 28, 2025
Expert Q&A

do sui have any robust websocket service to subscribe events on certain contract?

do sui have any robust websocket service to subscribe events on certain contract?

  • Sui
0
11
Share
Comments
.

Answers

11
0xduckmove.
Jul 31 2025, 09:57

Yes, Sui provides a websocket service for subscribing to events related to specific contracts. The Sui network supports a WebSocket API that allows you to subscribe to events such as transaction updates, changes to accounts, or contract-specific events.

The key components to interact with Sui's WebSocket API for event subscriptions are:

Sui Client: You can use a Sui client library (such as sui.js for JavaScript) to establish a WebSocket connection and subscribe to events. Event Types: The API allows you to listen to a variety of event types such as transaction confirmation, object state changes, and contract-related events. To subscribe to contract events specifically, you would likely be listening for events related to specific contract addresses or smart contract interactions.

Here’s a general flow:

Connect to the WebSocket endpoint. Subscribe to events based on contract addresses. Handle incoming event data based on your requirements. For detailed documentation on how to set this up, you can refer to Sui's official documentation or SDKs.

Would you like more details on how to implement this in code or a specific example?

3
Best Answer
Comments
.
Owen.
Owen4662
Jul 30 2025, 03:18

Sui does not have a native WebSocket service for event subscription. Instead, use the sui_subscribeEvent RPC method via WebSocket-compatible endpoints provided by third-party infrastructure providers (e.g., Chainstack, QuickNode) to subscribe to events filtered by package, module, or sender. This allows real-time monitoring of contract events. Public full nodes may not support persistent WebSocket connections, so relying on dedicated RPC providers ensures robustness.

6
Comments
.
Benjamin XDV.
Jul 30 2025, 09:42

The Sui blockchain currently does not offer a native WebSocket service for real-time event subscriptions. However, you can use Sui's Event API with long-polling or third-party services like Chainbase or QuickNode for WebSocket-based event streaming. Alternatively, set up a custom solution using Sui’s RPC endpoints combined with a WebSocket server (e.g., Socket.io or GraphQL subscriptions). For contract-specific events, filter by moveEventType or senderAddress in your queries.

6
Comments
.
Paul.
Paul4340
Jul 31 2025, 09:52

Yes, Sui provides a websocket service for subscribing to events related to specific contracts. The Sui network supports a WebSocket API that allows you to subscribe to events such as transaction updates, changes to accounts, or contract-specific events.

The key components to interact with Sui's WebSocket API for event subscriptions are:

  • Sui Client: You can use a Sui client library (such as sui.js for JavaScript) to establish a WebSocket connection and subscribe to events.
  • Event Types: The API allows you to listen to a variety of event types such as transaction confirmation, object state changes, and contract-related events.

To subscribe to contract events specifically, you would likely be listening for events related to specific contract addresses or smart contract interactions.

Here’s a general flow:

  1. Connect to the WebSocket endpoint.
  2. Subscribe to events based on contract addresses.
  3. Handle incoming event data based on your requirements.

For detailed documentation on how to set this up, you can refer to Sui's official documentation or SDKs.

Would you like more details on how to implement this in code or a specific example?

6
Comments
.
Arnold.
Arnold3036
Jul 30 2025, 08:25

Yes! Use Sui's WebSocket API to subscribe to contract events:

import { SuiClient } from '@mysten/sui.js/client';

const client = new SuiClient({ url: 'wss://fullnode.mainnet.sui.io:443' });

// Subscribe to events for a specific contract
const unsubscribe = client.subscribeEvent({
  filter: {
    MoveEventType: '0xYOUR_CONTRACT_ADDRESS::module::EventType',
  },
  onMessage(event) {
    console.log('New Event:', event);
  },
});

// Later, unsubscribe
unsubscribe();

Key Notes

  • Works for: Move events, object changes, transactions.
  • Filter by: Contract address, event type, sender.
  • Fallback: If WS fails, use HTTP polling (queryEvents).
5
Comments
.
Alya.
Alya-14
Jul 31 2025, 06:22

Yes, Sui supports WebSocket subscriptions via sui_subscribe to listen to events from specific contracts using MoveEvent filtering by package or module. Use @mysten/sui.js for easy integration.

4
Comments
.
shamueely.
Jul 28 2025, 11:28

Yes, Sui provides a robust WebSocket service that allows you to subscribe to real-time events, including those emitted by specific contracts (i.e., Move modules). This is handled through the Sui JSON-RPC over WebSocket protocol, which supports sui_subscribeEvent and sui_subscribeTransaction methods.

You can subscribe to:

  • All events on the network.
  • Events from a specific Move module or function.
  • Events that match a specific sender, object ID, or type.

For example, to listen to events from a contract you deployed, you'd subscribe using the MoveEvent type or filter by package, module, or eventType.

Here's a simplified TypeScript usage:

const ws = new WebSocket('wss://fullnode.testnet.sui.io');

ws.onopen = () => {
  const payload = {
    jsonrpc: "2.0",
    id: 1,
    method: "sui_subscribeEvent",
    params: [
      {
        MoveEventType: "0xYourPackageId::YourModule::YourEventName"
      }
    ]
  };
  ws.send(JSON.stringify(payload));
};

ws.onmessage = (msg) => {
  console.log("Received event:", JSON.parse(msg.data));
};

Make sure to replace YourPackageId, YourModule, and YourEventName with your actual values. This will stream events as they are emitted from your contract.

For advanced filters and more event types, consult the official WebSocket spec here: 👉 https://docs.sui.io/sui-jsonrpc#websocket-subscriptions

1
Comments
.
Bekky.
Bekky1762
Jul 29 2025, 13:28

Yes, Sui offers robust WebSocket support for event subscriptions.

1. Using Sui's WebSocket API

import { SuiClient } from '@mysten/sui.js/client';

const client = new SuiClient({ 
  url: 'wss://fullnode.mainnet.sui.io:443' 
});

// Subscribe to events from a specific contract
const unsubscribe = client.subscribeEvent({
  filter: {
    MoveEventType: '0xYOUR_PACKAGE_ID::module_name::EventType'
  },
  onMessage(event) {
    console.log('New event:', event);
  }
});

// Later, call unsubscribe() to stop

Key Features

Real-time updates
Filter by:

  • Contract (MoveEventType)
  • Sender
  • Transaction module
    Auto-reconnection

Alternative (JSON-RPC)

curl -X POST https://fullnode.mainnet.sui.io \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "suix_subscribeEvent",
    "params": [{
      "MoveEventType": "0xYOUR_PACKAGE_ID::module::Event"
    }],
    "id": 1
  }'
1
Comments
.

Do you know the answer?

Please log in and share it.