-
Notifications
You must be signed in to change notification settings - Fork 61
feat(toncenter): document Streaming API v2 #2049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b6a56af
feat(toncenter): document Streaming API v2
novusnota 23229cf
fix
novusnota f8fdc0a
fix link
novusnota 7fb6161
fixes
novusnota b3d6c22
Merge branch 'main' into closes-1984/big-brother-is-streaming-you
novusnota 02209e3
Apply suggestion
novusnota 19e7e89
Merge branch 'main' into closes-1984/big-brother-is-streaming-you
novusnota 93b900c
security comment 2, plus better discoverability of the action_types
novusnota 9ba549f
security comment 1: downtime
novusnota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| --- | ||
| title: "Streaming API overview" | ||
| sidebarTitle: "Overview" | ||
| --- | ||
|
|
||
| import { Aside } from '/snippets/aside.jsx'; | ||
|
|
||
| The TON Center **Streaming API** (v2) provides developer access to TON Blockchain through [Server-Sent Events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events) and [WebSockets](https://en.wikipedia.org/wiki/WebSocket). It delivers low-latency, real-time updates on transactions and actions observed on the TON blockchain. Clients can subscribe to updates for monitoring a wallet, some contract addresses, or a specific trace of transactions. | ||
|
|
||
| Streaming API serves as a real-time, streaming version of the [indexed access layer (API v3)](/ecosystem/api/toncenter/v3/overview). Use it when building wallets, explorers, monitoring systems, or automation tools. | ||
|
|
||
| <Aside | ||
| type="caution" | ||
| title="Gap recovery" | ||
| > | ||
| The Streaming API does not recover past events; it only tracks current ones. As such, network interruptions, client restarts, or brief service downtime can cause missed events. | ||
|
|
||
| When application state or business logic depends on a complete event sequence, resynchronize with historical data by polling [API v3](/ecosystem/api/toncenter/v3/overview) after reconnecting. | ||
| </Aside> | ||
|
|
||
| <Aside | ||
| type="note" | ||
| title="Version naming" | ||
| > | ||
| The [API v2](/ecosystem/api/toncenter/v2/overview) and [API v3](/ecosystem/api/toncenter/v3/overview) include their major version numbers in their product names. For the Streaming API, `v2` means the current protocol version and doesn't refer to different APIs. | ||
| </Aside> | ||
|
|
||
novusnota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Event groups | ||
|
|
||
| The Streaming API emits the following event groups: | ||
|
|
||
| - Trace-based events: `transactions`, `actions`, `trace` | ||
| - State updates: `account_state_change` and `jettons_change` | ||
| - Invalidation signal: `trace_invalidated` | ||
|
|
||
| The [event types section](/ecosystem/api/toncenter/streaming/reference#event-types) and [notification schemas section](/ecosystem/api/toncenter/streaming/reference#notification-schemas) provide the exact payload structure for each event. | ||
|
|
||
| ## Finality model | ||
|
|
||
| Trace-based events carry a `finality` field according to their finality level: | ||
|
|
||
| ```json | ||
| "finality": "pending" | "confirmed" | "finalized" | ||
| ``` | ||
|
|
||
| Each trace moves through the following monotonic lifecycle: | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| pending --> confirmed --> finalized | ||
| pending --> trace_invalidated | ||
| confirmed --> trace_invalidated | ||
| ``` | ||
|
|
||
| - `pending` — result of emulation or speculative execution. This state can be invalidated (`trace_invalidated`). | ||
| - `confirmed` — trace or transactions are included in a candidate shard block. Rollback chance is very small, but still possible. | ||
| - `finalized` — committed in the masterchain and will not be updated nor invalidated. | ||
|
|
||
| Non-trace events behave differently: | ||
|
|
||
| - `account_state_change` and `jettons_change` are emitted only when `finality` field is set to either `confirmed` or `finalized`. | ||
| - `trace_invalidated` applies to previously emitted trace-based data and is not emitted after `finalized`. | ||
|
|
||
| ## Delivery behavior | ||
|
|
||
| The `min_finality` field is used to control how early the server emits trace-based updates: | ||
|
|
||
| - `pending` — receive every trace snapshot as it moves from `pending` to `confirmed` to `finalized`. | ||
| - `confirmed` — skip pure emulation results and start at `confirmed` or later. | ||
| - `finalized` — receive only finalized trace-based events. | ||
|
|
||
| Choose the setting based on the tolerance for speculative data: | ||
|
|
||
| - Use `pending` for the lowest latency. | ||
| - Use `confirmed` for lower rollback risk with near-real-time delivery. | ||
| - Use `finalized` when only settled data is acceptable. | ||
|
|
||
| The [delivery semantics section](/ecosystem/api/toncenter/streaming/reference#delivery-semantics) and [event invalidation section](/ecosystem/api/toncenter/streaming/reference#event-invalidation) document the exact behavior for each event type. | ||
|
|
||
| ## Supported interfaces | ||
|
|
||
| The Streaming API exposes two transports: SSE and a WebSocket. Choose either of the transports to proceed with its usage: | ||
|
|
||
| <Columns cols={2}> | ||
| <Card | ||
| title="SSE: Server-Sent Events" | ||
| icon="server" | ||
| href="/ecosystem/api/toncenter/streaming/sse" | ||
| > | ||
| Recommended for browser environments or clients that prefer HTTP streaming and a fixed subscription. | ||
| </Card> | ||
|
|
||
| <Card | ||
| title="WebSocket" | ||
| icon="signal-stream" | ||
| href="/ecosystem/api/toncenter/streaming/wss" | ||
| > | ||
novusnota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Preferred for persistent, bidirectional communication with dynamic subscription patterns. | ||
| </Card> | ||
novusnota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </Columns> | ||
|
|
||
| ## See also | ||
|
|
||
| - [Notification reference](/ecosystem/api/toncenter/streaming/reference) | ||
| - [API key](/ecosystem/api/toncenter/get-api-key) | ||
| - [API authentication](/ecosystem/api/toncenter/v3-authentication) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.