Integrating a secure and efficient wallet connection into your decentralized application (DApp) is crucial for delivering a seamless user experience on the TON (The Open Network) blockchain. This guide provides a comprehensive walkthrough of using the OKX Ton Connect SDK to enable wallet connectivity, transaction handling, and real-time state monitoring β all while minimizing development overhead and supporting cross-platform functionality.
Whether you're building a Web3-powered mini-app, integrating with Telegram environments, or launching a full-scale DApp on TON, this SDK streamlines integration with minimal setup.
π Discover how easy it is to integrate wallet connectivity into your DApp today.
Core Keywords
- Ton Connect SDK
- OKX Wallet Integration
- DApp Wallet Connection
- TON Blockchain API
- Web3 Wallet Integration
- Send Transaction on TON
- Wallet State Monitoring
- Connect Wallet via SDK
These keywords reflect the central themes of this guide and are naturally integrated throughout to align with search intent and enhance SEO performance.
SDK Installation
You can install the OKX Ton Connect SDK using either CDN or npm, depending on your project's architecture and deployment needs.
Using CDN
To include the SDK via CDN, add the following script tag to your HTML file:
<script src="https://cdn.okx.com/sdk/okx-ton-connect-sdk/latest.js"></script>You may replace latest with a specific version number such as 1.3.7 for better stability and version control.
Once loaded, the SDK becomes available as a global object:
const connector = new OKXTonConnectSDK.OKXTonConnect();This method is ideal for frontend-only projects or rapid prototyping where build tools arenβt in use.
Using npm
For modern JavaScript applications using package managers, run:
npm install @okxweb3/okx-ton-connect-sdkThen import it in your code:
import { OKXTonConnect } from '@okxweb3/okx-ton-connect-sdk';Using npm allows for better tree-shaking, TypeScript support, and integration with bundlers like Webpack or Vite.
π Get started with seamless wallet integration in under 5 minutes.
Initialization
Before connecting to a wallet, initialize the SDK with your appβs metadata:
const okxTonConnect = new OKXTonConnect({
metaData: {
name: 'My DApp', // Your app's display name
icon: 'https://example.com/icon.png' // 180x180px PNG recommended
}
});Parameters
metaData(object)name(string): A non-unique name shown during connection prompts.icon(string): Direct URL to your app icon (supports PNG or ICO; 180Γ180px recommended).
This step ensures users recognize your application when authorizing wallet access, enhancing trust and conversion rates.
Connect to Wallet
Establish a secure connection to retrieve the userβs wallet address and enable transaction signing.
await okxTonConnect.connect({
tonProof: 'custom-proof-data', // Optional: used for authentication
redirect: 'tg://resolve...', // Required in Telegram mini-apps
openUniversalLink: true // Recommended on mobile
});Parameters
tonProof(string, optional): Data signed by the wallet for authentication.redirect(string, optional): Deeplink used post-signing (essential in Telegram).openUniversalLink(boolean, optional): Iftrue, opens the OKX App directly; if not installed, redirects to download page.
Recommendations
- Mobile (Browser or Telegram): Set
openUniversalLink: truefor smooth app handoff. - Desktop: Set
openUniversalLink: false, generate a QR code from the returned link, and let users scan via the OKX mobile app.
The method returns a universal link that can be rendered as a QR code on desktop for easy mobile pairing.
Restore Connection
Preserve user sessions by restoring previous connections without re-authentication:
await okxTonConnect.restoreConnection();This asynchronous method checks for an existing session and reconnects automatically if valid. Ideal for improving UX by reducing repeated login prompts.
No parameters required. Use this during app initialization to maintain continuity.
Disconnect Wallet
Terminate the current session securely:
await okxTonConnect.disconnect();This removes all local session data and disconnects the wallet. Always call this before attempting to switch accounts or log out.
Check Connection Status
Verify whether a wallet is currently connected:
const isConnected = okxTonConnect.connected;Returns true if connected, false otherwise. Useful for conditional rendering in UI components.
Send Transaction
Initiate and sign transactions through the connected wallet:
const result = await okxTonConnect.sendTransaction({
validUntil: Math.floor(Date.now() / 1000) + 600,
messages: [
{
address: 'UQB...',
amount: '500000000', // in nanotons
payload: 'base64-encoded-boc'
}
]
}, {
onRequestSent: () => console.log('Signature request sent')
});Parameters
transactionvalidUntil: Unix timestamp after which the transaction expires.from: Sender address (optional; defaults to connected wallet).messages: Array of 1β4 message objects containing recipient, amount, and optional payload.
optionsonRequestSent: Callback triggered when signature request is dispatched.
Returns a Promise resolving to { boc: string }, the signed transaction in Base64-encoded BoC format.
Monitor Wallet State Changes
Listen for real-time updates on connection and transaction status:
const unsubscribe = okxTonConnect.onStatusChange(
(walletInfo) => {
console.log('Wallet connected:', walletInfo.account.address);
},
(error) => {
console.error('Connection error:', error.message);
}
);
// Call later to clean up listener
unsubscribe();Wallet Info Object Includes:
device: Wallet platform (iOS/Android)appName: Name of the wallet (e.g., "OKX Wallet")account: Contains address, public key, chain ID (-239for TON)connectItems: Proof data forton_proofauthentication
Use this to update UI states dynamically and respond to authentication events.
Listen to Events
Subscribe to specific lifecycle events for granular control:
window.addEventListener('OKX_TON_CONNECTION_COMPLETED', () => {
console.log('Wallet connected successfully');
});
window.addEventListener('OKX_TON_TRANSACTION_SIGNED', () => {
alert('Transaction confirmed!');
});Supported Events
OKX_TON_CONNECTION_STARTEDβ Connection initiatedOKX_TON_CONNECTION_COMPLETEDβ Successfully connectedOKX_TON_CONNECTION_ERRORβ User rejected or error occurredOKX_TON_DISCONNECTIONβ User disconnectedOKX_TON_TRANSACTION_SENT_FOR_SIGNATUREβ Signing request sentOKX_TON_TRANSACTION_SIGNEDβ Transaction signed successfully
These events empower developers to create responsive interfaces that react instantly to user actions.
Get Account & Wallet Information
Retrieve current account details:
const account = okxTonConnect.getAccount(); // Returns account object
const wallet = okxTonConnect.getWallet(); // Returns wallet infoUseful for displaying user balances, profile info, or transaction history within your DApp.
Error Handling
Common error codes you might encounter:
UNKNOWN_ERROR: Unexpected failureALREADY_CONNECTED_ERROR: Attempted duplicate connectionNOT_CONNECTED_ERROR: Action requires active connectionUSER_REJECTS_ERROR: User denied requestMETHOD_NOT_SUPPORTED: Feature not available on current platformCONNECTION_ERROR: Network or handshake failure
Handle these gracefully in your UI to improve user retention and trust.
Frequently Asked Questions (FAQ)
Q: Can I use this SDK outside of Telegram mini-apps?
A: Yes. While optimized for Telegram environments, the SDK works across web browsers and mobile apps supporting universal links.
Q: Is user data stored by OKX during connection?
A: No. The connection is non-custodial and privacy-preserving. Only public addresses and signatures are shared.
Q: How do I handle failed transaction signings?
A: Listen for the OKX_TON_TRANSACTION_SIGNING_FAILED event or catch errors in the promise chain.
Q: Does this support multiple wallets?
A: You must disconnect the current wallet before connecting a new one. Multi-wallet management must be handled at the app level.
Q: Can I customize the connection UI?
A: The connection flow is managed by the OKX App, but you can customize prompts via metadata (name, icon).
Q: Is there a testnet version available?
A: Yes. The SDK supports both mainnet and testnet configurations through chain detection.
π Start integrating with confidence using reliable Web3 infrastructure.