TRON Wallet Integration Guide: Connect Web3 Wallets & DEX API

·

Installation & Initialization

To integrate OKX Connect with your DApp, ensure the OKX App is updated to version 6.96.0 or later. Use npm for seamless integration:

npm install okx-connect

Before connecting wallets, create a UI provider object for wallet interactions like transactions and signatures.

Required Parameters

Returns

Example

const provider = new OKXUniversalConnectUI({
  dappMetaData: {
    name: "MyDApp",
    icon: "https://example.com/icon.png"
  }
});

Connecting a Wallet

Establish a wallet connection to retrieve addresses for signing transactions.

Parameters

Returns

Example

const session = await provider.connect({
  namespaces: { tron: { chains: ["tron:mainnet"] } }
});

Transaction Preparation

Create an OKXTronProvider instance using okxUniversalConnectUI:

const tronProvider = new OKXTronProvider(provider);

Account Information

Fetch wallet details for a specified chain.

Parameters

Returns

Example

const account = await tronProvider.getAccount("tron:mainnet");

Signing Messages

Parameters

Returns

Example

const signature = await tronProvider.signMessage("Hello, TRON!");

Signing Transactions

Parameters

Returns

Example

const signedTx = await tronProvider.signTransaction(txData);

Broadcasting Transactions

Parameters

Returns

Example

const txHash = await tronProvider.signAndSendTransaction(txData);

Disconnecting Wallets

Terminate the current session to switch or disconnect wallets:

await provider.disconnect();

Event Handling

Listen for wallet events (e.g., session updates or disconnects):

provider.on("session_update", (session) => {
  console.log("Session updated:", session);
});

Error Codes

CodeDescription
UNKNOWN_ERRORUnexpected error.
ALREADY_CONNECTED_ERRORWallet is already connected.
USER_REJECTS_ERRORUser declined the request.
CHAIN_NOT_SUPPORTEDUnsupported blockchain.

👉 Explore more Web3 integrations


FAQs

Q: How do I handle unsupported chains?
A: Use optionalNamespaces to proceed with partial support or check chains via provider.getSupportedChains().

Q: Can I customize the wallet connection UI?
A: Yes, configure uiPreferences for themes and language.

Q: What’s the recommended return strategy for Telegram Mini Apps?
A: Set tmaReturnUrl: "back" to close the wallet post-signature.

👉 Get API keys for DEX integration