Skip to main content
To work with Toncoin, the wallet service needs to handle contract balances and perform transfers initiated from dApps and from within the wallet service itself.

Balances

Blockchain state changes constantly as new blocks are produced. This has implications for when and how to check TON wallet contract balances:
  • Discrete one-off checks have almost no value on their own — the state might change immediately after the query completes, invalidating its results. Thus, such checks are only practical when handling transaction requests.
  • Continuous monitoring is useful for UI display, showing the most recent balance to users, but should not be used for transaction confirmations.
Notice that both cases require querying the blockchain data via the API client set during the WalletKit initialization. Obtain and provide the key from the selected client to access higher requests-per-second limits.

On-demand balance check

Use the getBalance() method to check the wallet contract balance in TON wallets managed by WalletKit. The balance is returned in nanoToncoin, with 1 Toncoin equal to 109 nanoToncoin.
TypeScript
The most practical use of one-off balance checks is right before approving a transaction request. At this point, the actual wallet contract balance usually is not less than the checked amount, though it might be higher if new funds arrived right after the check.
TypeScript

Continuous balance monitoring

Poll the balance at regular intervals to keep the displayed value up to date. Use an appropriate interval based on UX requirements — shorter intervals provide fresher data but increase API usage. This example should be modified according to the wallet service’s logic:
TypeScript

Transfers from dApps

When a connected dApp requests a Toncoin transfer, the wallet service follows this flow:

Emulation and preview

WalletKit tries to automatically emulate every incoming transaction request before presenting it to the user. The emulation result is available in the event.preview.data object, which can be undefined if emulation was skipped:
TypeScript

Approve or reject

After showing the preview, handle the user’s decision:
TypeScript

Confirm transaction delivery

TON achieves transaction finality after a single masterchain block confirmation, where new blocks are produced approximately every 3 seconds. Once a transaction appears in a masterchain block, it becomes irreversible. Therefore, to reliably confirm the transaction delivery and status, one needs to check whether a transaction has achieved masterchain finality using the selected API client. That said, the wallet service should not block the UI while waiting for such confirmation. After all, with continuous wallet balance monitoring and subsequent transaction requests, users will receive the latest information either way. Confirmations are only needed to reliably display a list of past transactions, including the most recent ones. For detailed transaction tracking and message lookups, the message lookup guide covers finding transactions by external message hash, waiting for confirmations, and applying message normalization.

Transfers in the wallet service

Transactions can be created directly from the wallet service (not from dApps) and fed into the regular approval flow via handleNewTransaction() method of the WalletKit. It creates a new transaction request event, enabling the same UI confirmation-to-transaction flow for both dApp-initiated and wallet-initiated transactions. This example should be modified according to the wallet service’s logic:
TypeScript

See also