API key is required by the SDK constructor. Get one at tonconsole.com.
Architecture
| Component | Description |
|---|---|
TonapiStreaming | Unified client — manages session, exposes .sse and .ws transports. |
TonapiSSE | One-way stream. HTTP GET, server pushes SSE events. |
TonapiWebSocket | Bidirectional. JSON-RPC 2.0 protocol over WebSocket. |
Subscriptions
Both transports expose the same four subscription methods with identical signatures:| Method | Event model | Description |
|---|---|---|
subscribe_transactions() | TransactionEvent | Finalized account transactions. |
subscribe_blocks() | BlockEvent | New blocks (filterable by workchain). |
subscribe_traces() | TraceEvent | Completed traces for account groups. |
subscribe_mempool() | MempoolEvent | Pending inbound messages. |
Endpoints
- SSE
- WebSocket
| Network | URL |
|---|---|
| Mainnet | https://tonapi.io/v2/sse/... |
| Testnet | https://testnet.tonapi.io/v2/sse/... |
Quick Example
streaming.sse with streaming.ws to switch to WebSocket — the API is identical.
Event Models
All models are PydanticBaseModel subclasses.
TransactionEvent
TransactionEvent
| Field | Type | Description |
|---|---|---|
account_id | str | Account address. |
lt | int | Logical time. |
tx_hash | str | Transaction hash. |
BlockEvent
BlockEvent
| Field | Type | Description |
|---|---|---|
workchain | int | Workchain ID. |
shard | str | Shard identifier. |
seqno | int | Block sequence number. |
root_hash | str | Block root hash. |
file_hash | str | Block file hash. |
TraceEvent
TraceEvent
| Field | Type | Description |
|---|---|---|
accounts | list[str] | Involved account addresses. |
hash | str | Trace hash. |
MempoolEvent
MempoolEvent
| Field | Type | Description |
|---|---|---|
boc | str | Base64-encoded BOC. |
involved_accounts | list[str] | None | Involved account addresses, if available. |
Streaming events are finalized on-chain. Mempool events (
MempoolEvent) represent pending messages — they may or may not result in a transaction.