Initialize the WalletKit, set up at least one TON wallet and handle connection requests before using examples on this page.
| Incoming request | WalletKit method to listen and process the request |
|---|---|
connect | onConnectRequest() |
disconnect | onDisconnect() |
transaction | onTransactionRequest() |
signData | onSignDataRequest() |
restoreConnection | None — this is a connection health check of the JS bridge |
| Any event error | onRequestError() |
Handle onTransactionRequest
If a dApp is connected to the wallet service, the former can request to initiate a blockchain transaction, which fires the transaction request over the bridge. The wallet service then handles it with the onTransactionRequest method of the WalletKit.
On TON, transactions are initiated by sending an external message to the TON wallet contract, which then processes it and sends internal messages as requested. To estimate money flows for planned transactions, WalletKit uses emulation via the configured API client, if supported.
The API client in use is determined by the optional
apiClient configuration parameter during WalletKit initialization. By default, the TON Center APIs are used, which provide rich emulation capabilities.TypeScript
Handle onSignDataRequest
If a dApp is connected to the wallet service, the former can request to sign data with the private key used by the selected TON wallet, which fires the signData request over the bridge. The wallet service then handles it with the onSignDataRequest method of the WalletKit.
The data to sign can be of several kinds: text, binary, or a raw cell.
TypeScript
Handle request errors
Upon any error in any of the requests, theonRequestError() method is invoked. Provide it with a callback function that would handle arbitrary errors and display useful information to the user.
TypeScript