Integrating blockchain functionality into decentralized applications (DApps) has become a critical step for developers aiming to deliver seamless user experiences. With the growing adoption of TRON-based applications and mini wallets—especially within ecosystems like Telegram—developers need robust, secure, and easy-to-implement tools. The OKX Connect SDK offers a streamlined way to integrate wallet connectivity, transaction signing, and account management for TRON-powered DApps.
This guide walks you through the complete integration process using the OKX Universal Provider, focusing on TRON chain support, secure message signing, transaction handling, and session management.
Installation and Initialization
Before connecting your DApp to any wallet, ensure your environment supports OKX Connect SDK version 6.96.0 or later. You can install it via npm:
npm install okx-connectOnce installed, initialize the OKXUniversalProvider object. This instance will serve as the foundation for all subsequent interactions, including wallet connection, transaction signing, and event listening.
Request Parameters
dappMetaData – Object
Metadata about your DApp displayed during the connection request.name: string – Name of your application (not used as a unique identifier).icon: string – URL pointing to your app’s icon in PNG or ICO format. SVG is not supported. For optimal display, use a 180x180px PNG image.
Return Value
OKXUniversalProvider– A provider instance enabling interaction with connected wallets.
👉 Get started with seamless TRON wallet integration today.
Connecting to a Wallet
To interact with user accounts, your DApp must establish a secure session by connecting to a wallet. During this process, users approve access to their accounts and selected chains.
Request Parameters
connectParams – ConnectParams
namespaces: [string: ConnectNamespace]
Required namespace(s) for connection. For TRON, use"tron". If any requested chain isn't supported by the wallet, the connection will be rejected.chains: string[] – List of chain IDs (e.g.,["tron:mainnet"])defaultChain?: string – Optional default chain for the session
optionalNamespaces: [string: ConnectNamespace]
Additional namespaces that are not required; connection proceeds even if unsupported.sessionConfig: object
Configuration options for post-connection behavior.redirect: string – Redirect URL after successful connection. For Telegram Mini Apps, use a deep link liketg://resolve.
Return Value
A Promise resolving to:
topic: string – Unique session identifiernamespaces: Record<string, SessionNamespace> – Connected namespace detailschains: string[] – Active chain IDsaccounts: string[] – User wallet addressesmethods: string[] – Supported RPC methodsdefaultChain?: string – Default chain for the sessionsessionConfig?: SessionConfig – Echoed configurationdappInfo: object – Your app's metadataname,icon,redirect?
Prepare the Transaction
Before sending transactions on the TRON network, instantiate the OKXTronProvider using the initialized OKXUniversalProvider. This prepares the environment for blockchain interactions such as balance queries, contract calls, and transaction submissions.
const tronProvider = new OKXTronProvider(okxUniversalProvider);This provider abstracts low-level communication with the wallet and ensures proper formatting for TRON-specific operations.
👉 Unlock advanced TRON DApp capabilities with one integration.
Get Account Information
Retrieve the connected user’s wallet address on a specific TRON network.
Request Parameters
chainId: string – Target chain (e.g.,"tron:mainnet")
Return Value
Object
address: string – The user’s wallet address
Example
const account = await okxUniversalProvider.request({
method: 'get_accounts',
params: { chainId: 'tron:mainnet' }
});
console.log(account.address); // e.g., "TQaA1..."Sign a Message
Allow users to sign arbitrary messages securely. Useful for authentication or proof-of-ownership flows.
Request Parameters
message: string – Message to sign (UTF-8 encoded)chainId?: string – Chain context (e.g.,"tron:mainnet")
Return Value
- Promise
– Hex-encoded signature
Example
const signature = await okxUniversalProvider.request({
method: 'personal_sign',
params: { message: 'Login to MyDApp', chainId: 'tron:mainnet' }
});Sign a Message V2
An enhanced version of message signing with stricter chain enforcement.
Request Parameters
message: stringchainId: string – Required chain ID
🔍 Note: Unlike the standard method, chainId is mandatory in V2.Return Value
- Promise
– Signature result
SignTransaction
Prepare and sign a TRON transaction without broadcasting it. Ideal for off-chain processing or batch operations.
Request Parameters
transaction: object – Raw transaction data (generated viaTronWeb.transactionBuilder)chainId?: string – Execution chain (e.g.,"tron:mainnet")
Return Value
- Promise – Signed transaction object
Example
const signedTx = await okxUniversalProvider.request({
method: 'tron_signTransaction',
params: { transaction: txData, chainId: 'tron:mainnet' }
});SignAndSendTransaction
Sign and broadcast a transaction directly to the TRON network in one step.
Request Parameters
transaction: object – Unsigned transactionchainId: string – Target chain
Return Value
- Promise
– Transaction hash upon success
Example
const txHash = await okxUniversalProvider.request({
method: 'tron_signAndSendTransaction',
params: { transaction: txData, chainId: 'tron:mainnet' }
});
console.log("Tx Hash:", txHash);👉 Maximize efficiency with one-click transaction signing.
Disconnect Wallet
Terminate the current session and revoke access to user accounts.
await okxUniversalProvider.disconnect();⚠️ Always disconnect before attempting to reconnect or switch wallets.
Event Handling
Listen to real-time events such as:
'connect'– Fired when wallet connects'disconnect'– Session ends'accountsChanged'– User switches accounts'chainChanged'– Active chain updates
Example:
okxUniversalProvider.on('accountsChanged', (accounts) => {
console.log('New accounts:', accounts);
});Error Codes
Common exceptions during integration:
OKX_CONNECT_ERROR_CODES.UNKNOWN_ERROR– Unexpected internal errorOKX_CONNECT_ERROR_CODES.ALREADY_CONNECTED_ERROR– Attempted duplicate connectionOKX_CONNECT_ERROR_CODES.NOT_CONNECTED_ERROR– Action requires active sessionOKX_CONNECT_ERROR_CODES.USER_REJECTS_ERROR– User denied requestOKX_CONNECT_ERROR_CODES.METHOD_NOT_SUPPORTED– Unsupported RPC methodOKX_CONNECT_ERROR_CODES.CHAIN_NOT_SUPPORTED– Chain not available in walletOKX_CONNECT_ERROR_CODES.WALLET_NOT_SUPPORTED– Incompatible wallet typeOKX_CONNECT_ERROR_CODES.CONNECTION_ERROR– Network or handshake failure
Handle these gracefully to improve UX and prevent crashes.
Frequently Asked Questions (FAQ)
Q: What TRON networks are supported?
A: Mainnet (tron:mainnet) and NILE testnet (tron:testnet) are fully supported.
Q: Can I connect from a Telegram Mini App?
A: Yes. Set the redirect parameter to a Telegram deep link like tg://resolve in session config.
Q: Is SVG icon supported during initialization?
A: No. Only PNG or ICO formats are accepted. Use a 180x180px PNG for best results.
Q: How do I switch between multiple connected wallets?
A: First call .disconnect() on the current session, then initiate a new connection.
Q: Are transactions automatically broadcast?
A: Only with signAndSendTransaction. Use signTransaction if you need manual control over broadcasting.
Q: What happens if a user rejects a transaction?
A: The promise rejects with USER_REJECTS_ERROR. Always wrap calls in try-catch blocks.
Core Keywords: TRON wallet integration, OKX Connect SDK, DApp wallet connection, sign transaction TRON, connect to mini wallet, DEX API documentation, blockchain SDK, Web3 integration