Integrating a secure and seamless wallet connection into your decentralized application (DApp) on the TON blockchain is essential for delivering a smooth user experience. Whether you're building a DEX, NFT marketplace, or Web3-powered service, leveraging the right SDK for Ton wallet integration ensures fast, reliable, and scalable interactions between your app and users’ wallets.
This guide walks you through the complete process of integrating the OKX Ton Connect SDK — from installation and initialization to sending transactions and monitoring real-time wallet events — all while following best practices in Web3 development.
Why Use the OKX Ton Connect SDK?
The OKX Ton Connect SDK streamlines the integration of TON-based wallets into your DApp. If you’ve previously worked with Ton Connect or OKX Connect, this SDK allows for backward compatibility and reduces development overhead. It supports simultaneous multi-network requests and provides robust tools for handling connections, transaction signing, and state monitoring.
By using this SDK, developers gain access to:
- QR-based and deep-linking connection flows
- Real-time wallet state updates
- Secure transaction signing via
tonProof - Cross-platform support (mobile, desktop, Telegram mini apps)
👉 Discover how easy it is to integrate Ton wallet connectivity today.
SDK Installation
You can install the OKX Ton Connect SDK via CDN or npm, depending on your project setup.
Install via CDN
Add the following script tag to your HTML file:
<script src="https://cdn.okx.com/sdk/ton-connect/latest.js"></script>You may replace latest with a specific version (e.g., 1.3.7) for better control over updates.
Once loaded, the SDK is available globally as OKXTonConnectSDK. Initialize it like so:
const connector = new OKXTonConnectSDK.OKXTonConnect();Install via npm
Run the following command in your terminal:
npm install @okxconnect/ton-connect-sdkThen import it into your project:
import { OKXTonConnect } from '@okxconnect/ton-connect-sdk';Initialize the SDK
Before connecting to a wallet, create an instance of the SDK with metadata about your application.
const okxTonConnect = new OKXTonConnect({
metaData: {
name: 'My DApp', // Your app's display name
icon: 'https://mydapp.com/icon.png' // 180x180px PNG recommended
}
});Parameters
metaData(object)name(string): The name of your DApp (does not need to be unique).icon(string): Public URL to your app’s icon in PNG or ICO format. A 180×180px PNG is ideal for clarity across devices.
This metadata appears during the wallet connection prompt, helping users identify your app securely.
Connect to a Wallet
To initiate a wallet connection and retrieve user account details:
okxTonConnect.connect({
tonProof: 'payload-for-proof',
redirect: 'tg://resolve...',
openUniversalLink: true
});Connection Options
tonProof(optional): String used for authentication viatonProofsignature.redirect(optional): Deep link to return users after signing (especially useful in Telegram environments).openUniversalLink(boolean, optional): On mobile, opens the OKX app directly. Recommended astrueon mobile; set tofalseon desktop to generate a scannable QR code.
Return Value
A promise resolving to a universal link string. On desktop, generate a QR code from this link so users can scan with the OKX app.
Best Practices
- Set
openUniversalLink: truein mobile browsers and Telegram. - On PC, use the returned link to render a QR code and close it automatically upon successful connection.
👉 See live demos of seamless Ton wallet connections in action.
Restore Previous Connection
If a user has connected before, restore their session without re-prompting:
await okxTonConnect.restoreConnection();This method checks for existing sessions and reconnects silently if valid — improving UX by reducing repeated interactions.
Use this when your DApp loads to maintain continuity.
Disconnect Wallet
To disconnect the current wallet and clear the session:
okxTonConnect.disconnect();Always disconnect before attempting to switch wallets.
Check Connection Status
Verify whether a wallet is currently connected:
if (okxTonConnect.connected) {
console.log('Wallet is connected');
}Useful for conditionally rendering UI elements like "Connect Wallet" buttons or balance displays.
Send a Transaction
Send blockchain transactions securely through the wallet:
const result = await okxTonConnect.sendTransaction({
validUntil: Math.floor(Date.now() / 1000) + 600, // 10 minutes from now
from: 'UQB...', // optional sender address
messages: [
{
address: 'UQC...', // recipient
amount: '500000000', // amount in nanotons
payload: 'base64-boc-payload' // optional
}
]
}, {
onRequestSent: () => console.log('Signature request sent')
});Parameters
transactionvalidUntil: Unix timestamp when the transaction expires.from: Sender address (defaults to connected wallet).messages: Array of 1–4 message objects containing destination, amount, and optional payload.
optionsonRequestSent: Callback triggered when the signature request is dispatched.
Returns
A Promise resolving to { boc: string }, where boc is the signed transaction body in Base64 format.
Monitor Wallet State Changes
Listen for real-time changes in wallet status:
const unsubscribe = okxTonConnect.onStatusChange(
(walletInfo) => {
console.log('Wallet connected:', walletInfo);
},
(error) => {
console.error('Connection error:', error);
}
);Wallet Info Object Includes:
device: Device type and OS (android,ios)appName: Name of the wallet appaccount: Connected account details including TON address, public key, and chain ID (-239)connectItems: Authentication data liketon_proof
Call unsubscribe() when no longer monitoring to free up resources.
Listen to Specific Events
Subscribe to granular events during the connection and transaction flow:
OKX_TON_CONNECTION_STARTEDOKX_TON_CONNECTION_COMPLETEDOKX_TON_CONNECTION_ERROROKX_TON_TRANSACTION_SENT_FOR_SIGNATUREOKX_TON_TRANSACTION_SIGNEDOKX_TON_DISCONNECTION
Example:
window.addEventListener('OKX_TON_CONNECTION_COMPLETED', () => {
console.log('User successfully connected wallet');
});These events help track user behavior and debug issues in real time.
Retrieve Account & Wallet Information
Get details about the connected account:
const account = okxTonConnect.getAccount();
console.log(account.address); // e.g., "UQB..."And wallet info:
const wallet = okxTonConnect.getWallet();
console.log(wallet.appName); // e.g., "OKX Wallet"Useful for personalizing user interfaces or logging analytics.
Error Handling
Common error codes include:
UNKNOWN_ERROR: Unexpected failureALREADY_CONNECTED_ERROR: Attempted duplicate connectionNOT_CONNECTED_ERROR: Action requires active connectionUSER_REJECTS_ERROR: User declined actionMETHOD_NOT_SUPPORTED: Unsupported SDK methodCONNECTION_ERROR: Network or protocol failure
Handle these gracefully in both UI and logs.
Frequently Asked Questions (FAQ)
What is Ton Connect SDK used for?
The Ton Connect SDK enables DApps to securely connect with TON-compatible wallets like OKX Wallet. It handles authentication, transaction signing, and real-time state updates.
Can I use this SDK in Telegram mini apps?
Yes. The SDK fully supports Telegram environments. Use the redirect parameter with Telegram deep links (tg://) to return users after signing.
Is it safe to use openUniversalLink on desktop?
No. Set openUniversalLink: false on desktop. Instead, generate a QR code from the returned universal link for mobile scanning.
How do I handle transaction timeouts?
Always set a reasonable validUntil timestamp (e.g., 5–10 minutes). Transactions submitted after this time will be rejected by the network.
Does the SDK support multiple wallets?
Not simultaneously. You must disconnect the current wallet before connecting a new one.
Can I customize the connection UI?
While the connection flow is handled by the OKX app, you can customize your DApp’s trigger buttons, loading states, and post-connect UI using event listeners.
👉 Start integrating with one of the most reliable Ton wallet SDKs available.
Core Keywords
- Ton wallet integration
- SDK for Ton
- Connect Ton wallet
- DEX API
- Web3 wallet connection
- Send TON transaction
- Wallet state monitoring
- Blockchain development tools
With robust features, clear documentation, and strong community support, the OKX Ton Connect SDK is a powerful choice for any developer building on the TON blockchain.