Skip to main content

Client

Session

Managing Webhooks

Subscriptions

A bound TonapiWebhook manages subscriptions without requiring an explicit webhook ID.

Account transactions

Other subscriptions

Deleting a webhook

Event Handling

The dispatcher manages handler registration, webhook lifecycle, and event routing.

Registering handlers

Decorators account_tx, opcode_msg, new_contracts accept *accounts for local filtering. All accept path for custom URL paths. Default paths: /account-tx, /mempool-msg, /opcode-msg, /new-contracts. Without decorators:

Lifecycle

setup() opens a session, creates webhooks per event type, subscribes, and stores tokens. teardown(cleanup) closes the session. When cleanup=True, unsubscribes from all events first. Subscriptions persist across restarts — on next setup(), existing webhooks are reused via ensure().
Registered paths (only event types with handlers):

Processing events

The method validates the token, parses the event with Pydantic, filters by account if specified, and injects dependencies.

Dependencies

Pass default dependencies via **kwargs in the constructor. Handlers receive only parameters they declare in their signature:
Per-request dependencies passed to process() take priority over constructor defaults. Handlers can be async or sync — the dispatcher awaits async results automatically.

Models