Skip to main content

State

StateMeaning
IDLENot connected.
CONNECTINGOpening the connection.
SUBSCRIBEDConnected, receiving notifications.
RECONNECTINGRe-establishing after a drop.
PropertyTypeDescription
stateConnectionStateCurrent connection state.
is_subscribedboolTrue when receiving notifications.
is_connectingboolTrue while opening the connection.
is_reconnectingboolTrue while re-establishing after a drop.
await sse.wait_subscribed(timeout=10.0)
Monitor transitions via on_state_change callback (sync or async):
def on_state(state: ConnectionState) -> None:
    print(state.value)

sse = ToncenterSSE("YOUR_API_KEY", Network.MAINNET, on_state_change=on_state)

Reconnect policy

Automatic reconnection on transient failures (5xx, 429, streaming transport errors, heartbeat timeout). Fatal errors (401, 403) stop immediately.
from toncenter.types import ReconnectPolicy

policy = ReconnectPolicy(
    max_reconnects=10,
    delay=2.0,
    max_delay=30.0,
    backoff_factor=2.0,
)
sse = ToncenterSSE("YOUR_API_KEY", Network.MAINNET, reconnect_policy=policy)
ParameterDefaultDescription
max_reconnects10Maximum attempts (-1 for unlimited).
delay2.0Initial delay in seconds.
max_delay30.0Upper bound for backoff delay.
backoff_factor2.0Multiplier applied on each attempt.
SSE: after a disconnect the server may hold the old session for up to a minute. An immediate reconnect can get 429.

Dynamic subscription

WebSocket only. SSE does not support dynamic subscription changes.
After start() establishes the initial connection, ToncenterWebSocket can modify subscriptions on the fly without reconnecting.

dynamic_subscribe

Replace the current subscription (snapshot semantics). All previously watched addresses/traces are replaced by the new set.
await ws.dynamic_subscribe(
    addresses=["0:ed1691307050047117b998b561d8de82d31fbf84910ced6eb5fc92e7485ef8a7"],
    min_finality=Finality.CONFIRMED,
    include_metadata=True,
)
ParameterDefaultDescription
addressesOptionalAddresses to watch (in any form).
trace_external_hash_normsOptionalTrace hashes to watch.
typesOptionalEvent types to receive.
min_finalityFinality.FINALIZEDMinimum finality level.
include_address_bookFalseInclude DNS-resolved names.
include_metadataFalseInclude token metadata.
action_typesOptionalFilter actions by type.
supported_action_typesOptionalAdvertise client-supported action types.

dynamic_unsubscribe

Remove addresses or trace hashes from the current subscription.
await ws.dynamic_unsubscribe(addresses=["EQDtFpEwcFAEcRe5mLVh2N6C0x-_hJEM7W61_JLnSF74p4q2"])
ParameterDefaultDescription
addressesOptionalAddresses to stop watching.
trace_external_hash_normsOptionalTrace hashes to stop watching.
Both methods raise RuntimeError if called without an active WebSocket connection, and ToncenterStreamingError if the server rejects the request.

Errors

See Reference for the full exception hierarchy. Streaming-specific exceptions:
ExceptionWhen
ToncenterStreamingErrorTransport-level error during streaming.
ToncenterConnectionLostErrorReconnect limit exhausted. Exposes .attempts count.
ToncenterUnauthorizedError (401) and ToncenterForbiddenError (403) are fatal — no reconnect is attempted.