Ton Connect SDK Guide: Wallet Integration & DEX API Documentation

·

Introduction

If you've previously used Ton Connect, this documentation allows for seamless continuation of your integration while minimizing development costs. Similarly, developers familiar with OKX Connect can transition to ProviderSDK for enhanced connectivity supporting concurrent multi-network requests.

SDK Installation

Install the SDK via CDN or NPM:

CDN Installation

Add this script to your HTML file:

<script src="https://cdn.jsdelivr.net/npm/@okx/web3@latest/dist/okx.web3.min.js"></script>

Replace "latest" with specific versions like "1.3.7" when needed. The global object OKXTonConnectSDK becomes available post-inclusion.

const connector = new OKXTonConnectSDK.OKXTonConnect();

NPM Installation

npm install @okx/web3

Initialization

Create an SDK instance before wallet connection:

new OKXTonConnect({
  metaData: {
    name: "YourAppName",
    icon: "https://your-app-icon.png"
  }
})

Parameters

Returns

Wallet Connection

Obtain wallet address and transaction signing parameters:

connect({
  tonProof: "optional_signature",
  redirect: "optional_deeplink",
  openUniversalLink: true // Default: false
})

Best Practices

Connection Management

Restore Session

restoreConnection()

Disconnect

disconnect()

Check Connection Status

connected()

Transaction Handling

Send transactions with:

sendTransaction({
  validUntil: UNIX_TIMESTAMP,
  messages: [{
    address: "recipient",
    amount: "1.5"
  }]
}, {
  onRequestSent: () => console.log("Request sent")
})

Event Monitoring

Track wallet state changes:

const unsubscribe = onStatusChange((walletInfo) => {
  console.log(walletInfo.account.address);
}, (err) => console.error(err));

Key Events

EventTrigger Condition
OKX_TON_CONNECTION_STARTEDConnection initiated
OKX_TON_TRANSACTION_SIGNEDSuccessful transaction signing

Error Handling

Common Errors

CodeDescription
UNKNOWN_ERRORUnspecified failure
USER_REJECTS_ERRORDeclined by user

FAQs

How do I switch connected wallets?

First disconnect the current wallet using disconnect(), then initiate a new connection.

Can I use this SDK for mobile and web?

Yes, with proper configuration of openUniversalLink for each environment.

What's the maximum protocol version supported?