UI Integration Guide: Connecting to TON App or Mini Wallet with API DEX Documentation

ยท

Overview

This guide explains how to integrate TON wallet connectivity into your DApp using our UI interface. Whether your users are accessing via Telegram or standalone browsers, they can seamlessly connect through the mobile App Wallet or OKX Mini Wallet.

Key Features:

Installation and Initialization

npm Installation

npm install @okx/ton-connect-ui

Initialization Parameters

Create the connection object with these configurable options:

new OKXTonConnectUI(
  dappMetaData,          // Your DApp metadata
  buttonRootId,          // HTML element ID for connect button
  actionsConfiguration,  // Transaction behavior settings
  uiPreferences,         // UI theme/language preferences
  language,              
  restoreConnection      // Auto-reconnect toggle
)

Parameter Details:

ParameterTypeDescription
metaData.namestringYour DApp's display name
metaData.iconstring180x180px PNG icon URL
buttonRootIdstringDOM element ID for button placement
actionsConfiguration.modalsarrayTransaction flow notifications
uiPreferences.themestringDARK/LIGHT/SYSTEM theme selection

Core Functionality

Wallet State Monitoring

Track connection events with real-time updates:

const unsubscribe = okxTonConnectUI.onStatusChange((wallet) => {
  if (wallet) {
    console.log('Connected to:', wallet.device.appName);
  }
});

// Remember to unsubscribe when done
unsubscribe();

Connection Flow

Users can connect either through:

  1. UI Button (if buttonRootId provided)
  2. Programmatic Call:

    await okxTonConnectUI.openModal();

Transaction Handling

Sending Transactions

const result = await okxTonConnectUI.sendTransaction(
  {
    validUntil: Date.now() + 1000000,
    messages: [{
      address: "EQ...",
      amount: "10000000",
      payload: "<boc>"
    }]
  },
  {
    modals: ['before', 'success'],
    returnStrategy: 'tg://resolve'
  }
);

Advanced Configuration

Dynamic Proof Configuration

// Set loading state
okxTonConnectUI.setConnectRequestParameters({
  state: 'loading'
});

// When ready
okxTonConnectUI.setConnectRequestParameters({
  state: 'ready',
  value: {
    tonProof: "<your_proof>"
  }
});

UI Customization

Update theme/language dynamically:

okxTonConnectUI.updateUIConfig({
  theme: 'DARK',
  language: 'fr_FR'
});

Event Handling

Monitor key wallet interactions:

EventDescription
OKX_UI_CONNECTION_STARTEDConnection initiated
OKX_UI_TRANSACTION_SIGNEDSuccessful transaction signing
OKX_UI_DISCONNECTIONWallet disconnected

๐Ÿ‘‰ Explore more integration examples

FAQ Section

Q: Can I use this with existing Ton Connect implementations?

A: Yes! The SDK maintains backward compatibility while adding new features.

Q: What's the difference between mobile and Mini Wallet connections?

A: Mobile opens the native OKX app, while Mini Wallet stays within Telegram with lighter functionality.

Q: How do I handle transaction errors?

A: Listen for OKX_UI_TRANSACTION_SIGNING_FAILED events and implement fallback logic.

๐Ÿ‘‰ Get support from our developer community

Error Reference

CodeMeaningSolution
1001Already ConnectedCheck getConnectedWallet() first
3002User RejectedAdd retry button in UI
4004Chain Not SupportedVerify network configuration

For production deployments, we recommend implementing comprehensive error handling with user guidance at each failure point.