Installation and Initialization
To begin integrating OKX Connect with your decentralized application (DApp), ensure you have the latest OKX App version (6.96.0 or higher). Follow these steps:
Install via npm:
npm install okx-connectCreate a UI interface object for wallet operations:
const connectUI = new OKXUniversalConnectUI({ dappMetaData: { name: "Your DApp Name", icon: "https://yourdomain.com/icon.png" // 180x180 PNG recommended }, actionsConfiguration: { modals: ['before'], // Transaction flow modals returnStrategy: 'tg://resolve', // For Telegram Mini Apps tmaReturnUrl: 'back' // Telegram wallet return behavior }, uiPreferences: { theme: "SYSTEM" // THEME.DARK, THEME.LIGHT, or "SYSTEM" }, language: "en_US" // Default language });
๐ Get started with Web3 wallet integration
Wallet Connection
Establish connection to retrieve wallet addresses for transaction signing:
const connection = await connectUI.connectWallet({
connectParams: {
namespaces: {
tron: {
chains: ["tron:mainnet"],
defaultChain: "tron:mainnet"
}
},
sessionConfig: {
redirect: "tg://resolve" // Post-connection redirect for Telegram
}
}
});Key Parameters:
chains: Supported network IDs (e.g., "tron:mainnet")redirect: Deeplink for post-connection navigationoptionalNamespaces: Additional supported chains
Transaction Processing
Creating Tron Provider
const provider = new OKXTronProvider(connectUI);Account Information Retrieval
const accountInfo = await provider.getAccountInfo("tron:mainnet");
// Returns: { address: "TronWalletAddress" }Message Signing
Standard Signature:
const signature = await provider.signMessage("Your message", "tron:mainnet");V2 Signature (Recommended):
const v2Signature = await provider.signMessageV2("Secured message", "tron:mainnet");Transaction Handling
Signing Only:
const signedTx = await provider.signTransaction(
{ /* Transaction object */ },
"tron:mainnet"
);Signing and Broadcasting:
const txHash = await provider.signAndSendTransaction(
{ /* Transaction object */ },
"tron:mainnet"
);๐ Explore advanced DEX API features
Wallet Disconnection
Terminate active sessions when switching wallets:
await connectUI.disconnect();Event Handling
Implement listeners for connection state changes:
connectUI.on('connection_update', (event) => {
console.log('Connection state:', event);
});Error Reference
| Error Code | Description |
|---|---|
| 1000 | Unknown error |
| 1001 | Wallet already connected |
| 1002 | No active wallet connection |
| 1003 | User rejected request |
| 1004 | Method not supported |
| 1005 | Chain not supported |
| 1006 | Wallet not supported |
| 1007 | Connection error |
FAQ Section
Q: How do I handle different Tron networks?
A: Specify chain IDs like "tron:mainnet" or "tron:nile" in your connection parameters.
Q: What's the difference between signMessage and signMessageV2?
A: signMessageV2 uses updated cryptographic standards with enhanced security.
Q: Can I customize the wallet connection UI?
A: Yes, through the uiPreferences object during initialization.
Q: How long do wallet sessions remain active?
A: Sessions persist until explicitly disconnected or when the DApp is closed.
Q: Is there a mobile SDK available?
A: Yes, the same npm package supports both web and mobile implementations.
Q: How do I test my integration before going live?
A: Use the Tron Nile testnet ("tron:nile") for development testing.