Installation & Initialization
To integrate OKX Connect into your DApp, ensure the OKX App is updated to version 6.88.0 or later. Use npm for seamless integration:
OKXUniversalProvider.init({ DAppMetaData: { name: "YourAppName", icon: "https://your-app-icon.png" } })Parameters
DAppMetaData(object):name(string): Application name (non-unique identifier).icon(string): URL to a 180x180px PNG/ICO icon (SVG not supported).
Returns
OKXUniversalProviderinstance.
Connecting a Wallet
Establish a wallet connection to retrieve addresses for signing transactions:
okxUniversalProvider.connect({
namespaces: {
"eip155": {
chains: ["chainId1", "chainId2"],
rpcMap: { "chainId1": "RPC_URL" }
}
},
sessionConfig: { redirect: "tg://resolve" }
});Key Parameters
chains: Array of EVM-compatible chain IDs.rpcMap: Custom RPC endpoints (EVM-only).redirect: Deeplink for post-connection routing (e.g., Telegram Mini Apps).
Returns
- Session details including accounts, supported methods, and active chains.
Checking Wallet Connection Status
Verify if a wallet is currently linked:
const isConnected = okxUniversalProvider.isConnected();
// Returns: booleanTransaction Preparation
Execute wallet requests like signing or sending transactions:
await okxUniversalProvider.request({
method: "eth_sendTransaction",
params: [transactionParams],
chain: "eip155:1"
});Supported Methods
personal_sign: Returns signature.eth_sendTransaction: Returns transaction hash.wallet_addEthereumChain: Adds custom networks.
Using Custom RPC Endpoints
Extend functionality by configuring RPC URLs during connect():
rpcMap: { "eip155:42161": "https://arbitrum-rpc.example.com" }Setting Default Networks
Define a fallback chain for unspecified operations:
defaultChain: "eip155:56" // BSC as defaultDisconnecting Wallets
Terminate active sessions before switching wallets:
okxUniversalProvider.disconnect();Event Handling
Subscribe to wallet events (e.g., session updates, chain changes):
okxUniversalProvider.on("accountsChanged", handleAccountChange);Error Codes
| Code | Description |
|---|---|
UNKNOWN_ERROR | Unexpected failure |
USER_REJECTS_ERROR | User declined action |
CHAIN_NOT_SUPPORTED | Unavailable chain ID |
CONNECTION_ERROR | Session disruption |
👉 Explore advanced Web3 integrations
FAQ
Q: How do I handle unsupported chains?
A: Use optionalNamespaces in connect() or prompt users to add the chain via wallet_addEthereumChain.
Q: Can I use SVG icons for DApp metadata?
A: No—only PNG/ICO formats are accepted (180x180px recommended).
Q: What happens if RPC URLs fail?
A: The SDK falls back to wallet-default RPCs where available.