UI Integration for Aptos: Connect to App or Mini Wallet and DEX API Documentation

ยท

In addition to the SDK, we offer a user-friendly UI interface for seamless wallet integration. If your DApp operates within Telegram, users can choose to:


Installation and Initialization

Ensure the OKX App is updated to version 6.92.0 or later for full functionality.

Integration Steps:

  1. Use npm to integrate OKX Connect into your DApp:

    npm install okx-connect
  2. Create a UI interface object to handle wallet connections and transactions.

Request Parameters:

| Parameter | Type | Description |
|-----------|------|-------------|
| dappMetaData | Object | App metadata (name, icon URL) |
| actionsConfiguration | Object | Modal display settings and return strategies |
| uiPreferences | Object | Theme (dark/light/system) and language (default: en_US) |

Example:

const ui = new OKXUniversalConnectUI({
  dappMetaData: {
    name: "My DApp",
    icon: "https://example.com/icon.png"
  },
  actionsConfiguration: {
    modals: ['before', 'success'],
    returnStrategy: 'tg://resolve'
  },
  uiPreferences: {
    theme: 'SYSTEM',
    language: 'en_US'
  }
});

Connecting to a Wallet

Request Parameters:

| Parameter | Description |
|-----------|-------------|
| namespaces | Required chains (e.g., eip155 for EVM, aptos for Aptos) |
| optionalNamespaces | Optional chains for fallback support |
| sessionConfig | Redirect URL post-connection (e.g., tg://resolve for Telegram) |

Return Value:

Example:

const session = await ui.connect({
  namespaces: {
    aptos: { chains: ['aptos:1'], defaultChain: 'aptos:1' }
  },
  sessionConfig: { redirect: 'tg://resolve' }
});

Wallet Signing

Methods:

  1. Sign Message:

    const signedMessage = await provider.signMessage({
      message: "Hello, Aptos!",
      nonce: "12345"
    }, 'aptos:1');
  2. Sign Transaction:

    const txHash = await provider.signAndSubmitTransaction(txData, 'aptos:1');

Key Parameters:


FAQ

How do I check if a wallet is connected?

const isConnected = provider.isConnected();

How do I disconnect a wallet?

provider.disconnect();

What are common error codes?

| Code | Description |
|------|-------------|
| UNKNOWN_ERROR | Unexpected issue |
| USER_REJECTS_ERROR | User declined the request |
| CHAIN_NOT_SUPPORTED | Unsupported blockchain |

๐Ÿ‘‰ Explore more about Aptos integration


Event Handling and Error Codes

Events:

Error Handling:

try {
  await provider.signTransaction(txData);
} catch (error) {
  console.error("Error:", error.code);
}

Best Practices

๐Ÿ‘‰ Get started with OKX Wallet