You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with the release [v1.17.0](https://github.com/multiversx/mx-api-service/releases/tag/v1.17.0) we introduced WebSocket Subscription functionality.
9
9
10
-
It is useful for subscribing to new events, rather than performing polling (requesting latest events with a given refresh period).
10
+
It is useful for subscribing to new events in real-time, rather than performing polling (requesting latest events with a given refresh period).
11
11
12
-
## Update Frequency and Duplicate Management
13
-
Subscribers receive the most recent events at regular intervals defined by the API.
12
+
## Update Frequency and Data Modes
14
13
15
-
This means:
16
-
* You are **not** notified only when new events occur.
14
+
The WebSocket API supports two primary modes of data consumption: **Latest Data** and **Fresh Data**.
17
15
18
-
* Instead, you receive an update every round (or according to the configured interval configured in MultiversX API).
16
+
### 1. Latest Data (Snapshot & Loop)
17
+
Subscribers receive the most recent events for a specific timeframe at regular intervals defined by the API.
18
+
***Behavior:** You receive an update every round (or configured interval).
19
+
***Content:** Each update contains the latest events for the requested buffer (e.g., latest 25 blocks).
20
+
***Duplicates:** Because of the repeating interval, **duplicate events may appear across batches**. It is the user’s responsibility to filter these duplicates.
19
21
20
-
* Each update contains the latest events for that timeframe.
21
-
22
-
*For example*:
23
-
24
-
If you subscribe to the latest 25 blocks, you will receive those 25 blocks every second.
25
-
Because of this repeating interval, **duplicate events may appear across batches**, and it is the user’s responsibility to filter or handle those duplicates on their side.
22
+
### 2. Fresh Data (Custom Real-time Streams)
23
+
Subscribers receive events strictly as they occur on the blockchain, filtered by specific criteria.
24
+
***Behavior:** You are notified immediately when a new event matches your filter.
25
+
***Content:** Data flows in real-time from the moment of subscription.
26
+
***Duplicates:****No duplicate events are sent.** You receive each item exactly once.
27
+
***Available Streams:** Only `CustomTransactions` and `CustomEvents` are supported in this mode.
26
28
27
29
## Rest API models compatibility
28
30
The MultiversX WebSocket Subscription API provides real-time blockchain data identical in structure to REST API responses:
29
31
30
-
```
31
-
https://api.multiversx.com/<resource>
32
-
https://devnet-api.multiversx.com/<resource>
33
-
https://testnet-api.multiversx.com/<resource>
32
+
```text
33
+
https://api.multiversx.com
34
+
https://devnet-api.multiversx.com
35
+
https://testnet-api.multiversx.com
34
36
```
35
37
36
38
All updates mirror REST responses and include a `<resource>Count` field representing **the total number of existing items at the moment the update was delivered**.
**Note:** This mode pushes the latest buffer of data repeatedly. **Duplicate events may appear across batches**, and it is the user’s responsibility to filter or handle those duplicates on their side.
86
90
87
-
- DTO payload table
88
-
- Single code block with connect + payload + subscribe + listen
To stop receiving updates for any stream, you must emit the corresponding unsubscribe event.
501
+
502
+
**The Rule:**
503
+
1. Add the prefix `un` to the subscription event name (e.g., `subscribeTransactions` → `unsubscribeTransactions`, `subscribeCustomTransactions` → `unsubscribeCustomTransactions`).
504
+
2. Send the **exact same payload** used for the subscription.
Unexpected behaviors, such as sending an invalid payload or exceeding the server's subscription limits, will trigger an `error` event emitted by the server.
0 commit comments