Seamless Web3 Integration with Aptos: Connect Apps and Mini Wallets via UI

·

Integrating Web3 functionality into your decentralized application (DApp) has never been easier. With a robust UI layer built on top of the SDK, developers can now offer users a smooth and intuitive experience when connecting wallets—especially within Telegram-based environments. Whether your DApp operates on desktop or inside Telegram, users can seamlessly connect via the native OKX App wallet or opt for the lightweight OKX Telegram Mini Wallet without leaving the chat interface.

This guide walks you through the complete process of initializing, connecting, signing transactions, and managing sessions using the OKX Universal Connect UI, with full support for Aptos blockchain integration.


Installation and Initialization

To begin integrating OKX Connect into your DApp, ensure that users have OKX App version 6.92.0 or higher installed. This version supports all necessary features for UI-based wallet interactions.

You can install the required package via npm:

npm install @okxweb3/connect

Before initiating any wallet connections, create an instance of OKXUniversalConnectUI. This object powers all subsequent actions including connection, transaction signing, and event handling.

Configuration Parameters

const ui = new OKXUniversalConnectUI({
  dappMetaData: {
    name: "My DApp", // Display name (not unique)
    icon: "https://mydapp.com/icon.png" // 180x180px PNG recommended
  },
  actionsConfiguration: {
    modals: 'all', // Show UI for 'before', 'success', 'error'
    returnStrategy: 'tg://resolve', // Deep link return strategy (for app wallets)
    tmaReturnUrl: 'back' // For Telegram Mini Apps; closes wallet after signing
  },
  uiPreferences: {
    theme: THEME.DARK // Options: LIGHT, DARK, SYSTEM
  },
  language: 'en_US' // Supported: zh_CN, es_ES, fr_FR, etc.
});

👉 Discover how easy it is to integrate Web3 into your DApp with powerful UI tools.


Connecting Wallets

The first step in any Web3 interaction is establishing a secure connection to the user’s wallet. This grants access to their public address and enables transaction signing.

Required Parameters

await ui.connect({
  namespaces: {
    aptos: {
      chains: ['aptos:1', 'aptos:2'],
      defaultChain: 'aptos:1'
    }
  },
  optionalNamespaces: {
    eip155: {
      chains: ['eip155:1']
    }
  },
  sessionConfig: {
    redirect: 'tg://resolve' // Useful for Telegram Mini Apps
  }
});

Response Object

Upon successful connection:

{
  topic: "session-topic-hash",
  namespaces: { aptos: { ... } },
  chains: ["aptos:1"],
  accounts: ["0x1a2b..."],
  methods: ["aptos_signMessage"],
  defaultChain: "aptos:1",
  dappInfo: {
    name: "My DApp",
    icon: "https://..."
  }
}

Connect and Sign in One Step

For enhanced user experience, combine wallet connection with immediate message signing—ideal for authentication flows.

Example Request

const result = await ui.connectAndSign({
  connectParams: { /* same as above */ },
  signRequest: [{
    method: "aptos_signMessage",
    chainId: "aptos:1",
    params: {
      message: "Login to My DApp",
      nonce: "unique-nonce-123"
    }
  }]
});

This triggers both connection and a signature request. The signed data is returned via the connect_signResponse event.


Check Wallet Connection Status

Determine whether a wallet is currently connected:

const isConnected = ui.isConnected();
if (isConnected) {
  console.log("Wallet is connected");
}

Use this to conditionally render UI elements like "Connect Wallet" buttons or user dashboards.


Prepare and Sign Transactions

After connecting, interact with the Aptos blockchain by preparing and signing transactions.

Step 1: Initialize Provider

const provider = new OKXAptosProvider(ui.provider);

Step 2: Get Address and Public Key

const account = await ui.getAccount({ chain: "aptos:1" });
// Returns { address: "0x...", publicKey: "0x..." }

Sign Messages

Authenticate users securely by requesting signed messages.

Parameters

const signature = await ui.sign({
  message: {
    address: true,
    application: true,
    chainId: true,
    message: "Welcome to My DApp!",
    nonce: "abc123"
  },
  chain: "aptos:1"
});

Output

{
  address: "0x1a2b...",
  fullMessage: "[Aptos]...",
  signature: "0xabc...",
  nonce: "abc123"
}

This method ensures phishing resistance by embedding domain, address, and chain context in the signed payload.


Sign Single Transaction

Request approval and sign a single Aptos transaction:

const signedTx = await ui.signTransaction({
  transaction: {
    data: {
      function: "0x1::coin::transfer",
      typeArguments: ["0x1::aptos_coin::AptosCoin"],
      functionArguments: ["0xreceiver", 100]
    }
  },
  chain: "aptos:1"
});

Returns a serialized signed transaction buffer ready for broadcasting.


Sign and Execute Multiple Transactions

Batch multiple operations and submit them in one flow:

const txHash = await ui.signAndSubmitTransactions({
  transactions: [tx1, tx2],
  chain: "aptos:1"
});

Returns the final transaction hash upon successful on-chain execution.

👉 See how multi-transaction signing boosts efficiency in DeFi apps.


Disconnect Wallet

Terminate the active session cleanly:

await ui.disconnect();

Always disconnect before attempting to reconnect or switch accounts.


Event Handling

Listen to real-time events for better UX feedback:

ui.on('connect', (data) => console.log('Connected:', data));
ui.on('disconnect', () => console.log('Session ended'));
ui.on('sign', (data) => console.log('Signed:', data));

Common events include:


Error Codes and Troubleshooting

Handle common issues gracefully using standardized error codes:

CodeMeaning
UNKNOWN_ERRORUnexpected failure
ALREADY_CONNECTED_ERRORPrevent duplicate connections
NOT_CONNECTED_ERROREnsure connection before actions
USER_REJECTS_ERRORUser denied request
CHAIN_NOT_SUPPORTEDChain not available in wallet
METHOD_NOT_SUPPORTEDFeature not implemented

Catch errors with try-catch blocks:

try {
  await ui.connect(params);
} catch (error) {
  if (error.code === OKX_CONNECT_ERROR_CODES.USER_REJECTS_ERROR) {
    alert("User rejected the connection.");
  }
}

Frequently Asked Questions (FAQ)

Q: Can I use this UI in non-Telegram environments?
A: Yes. While optimized for Telegram Mini Apps, the UI works across web and mobile platforms where OKX Wallet is supported.

Q: What chains does this support besides Aptos?
A: The system supports EVM chains via eip155 namespace, enabling cross-chain DApps with optional fallbacks.

Q: Is user data stored during connection?
A: No. All data remains client-side. The connection is peer-to-peer and privacy-preserving.

Q: How do I handle language localization?
A: Set the language parameter during initialization. Supported locales include English, Chinese, Spanish, French, Arabic, and more.

Q: Can I customize the theme?
A: Yes. Choose from THEME.LIGHT, THEME.DARK, or SYSTEM to match your app’s design.

Q: What happens if a user updates their wallet?
A: Sessions persist unless revoked. Always check connection status before critical operations.


Final Thoughts

By leveraging the OKX Universal Connect UI, developers gain a powerful, modular toolkit for integrating Aptos-based DApps with minimal friction. From seamless Telegram Mini Wallet support to robust error handling and multi-transaction batching, this solution accelerates time-to-market while ensuring security and usability.

Whether you're building a DeFi protocol, NFT marketplace, or social DApp on Aptos, this integration path offers a future-proof foundation for Web3 engagement.

👉 Start building smarter Web3 experiences today with full UI integration.