Installation and Initialization
Ensure your OKX App is updated to version 6.88.0 or later for seamless integration.
To integrate OKX Connect into your DApp, use npm:
npm install @okx/web3-connectBefore connecting, initialize the provider:
OKXUniversalProvider.init({
DAppMetaData: {
name: "YourAppName", // Non-unique identifier
icon: "https://your-app-icon.png" // 180x180px PNG recommended
}
});Parameters:
DAppMetaData(object):name(string): Application name.icon(string): URL of the app icon (PNG/ICO formats only).
Returns:
OKXUniversalProviderobject.
Connect to Wallet
Use connect() to retrieve the wallet address for transaction signing:
okxUniversalProvider.connect(connectParams: ConnectParams);Parameters:
connectParams(object):namespaces: EVM key iseip155. Unsupported chains will be rejected.chains: Array of chain IDs (e.g.,["eip155:1"]for Ethereum Mainnet).optionalNamespaces: For custom networks (e.g.,["eip155:137"]for Polygon).redirect: Deeplink for post-connection redirection (e.g.,tg://resolvefor Telegram Mini Apps).
Returns:
- Session details including
accounts,chains, and supportedmethods.
Check Wallet Connection Status
Verify connectivity with:
const isConnected = okxUniversalProvider.isConnected();Returns:
boolean(true/false).
Send Transactions and Signatures
Call wallet methods like personal_sign or eth_sendTransaction:
okxUniversalProvider.request({
method: "personal_sign",
params: [message, account],
chain: "eip155:1"
});Supported Methods:
personal_sign: Returns signature string.eth_sendTransaction: Returns transaction hash.wallet_switchEthereumChain: Changes the active chain.
Custom RPC Configuration
Configure RPC endpoints in connectParams.rpcMap for advanced EVM requests:
rpcMap: {
"eip155:1": "https://mainnet-rpc.com",
"eip155:137": "https://polygon-rpc.com"
}Set Default Network
Specify a default chain for operations:
defaultChain: "eip155:1" // Ethereum MainnetDisconnect Wallet
Terminate the session:
okxUniversalProvider.disconnect();Error Handling
| Error Code | Description |
|------------|-------------|
| UNKNOWN_ERROR | Unexpected issue. |
| USER_REJECTS_ERROR | User declined the request. |
| CHAIN_NOT_SUPPORTED | Unsupported chain ID. |
FAQs
1. How do I handle unsupported chains?
Add the chain to optionalNamespaces or use wallet_addEthereumChain to prompt the user.
2. Can SVG icons be used for DApp metadata?
No. Use PNG/ICO formats (180x180px recommended).
3. What’s the difference between eth_accounts and eth_requestAccounts?
Both return addresses, but eth_requestAccounts triggers a wallet connection prompt if not already connected.
👉 Explore more OKX Web3 features
This guide ensures EVM-compatible wallet integration with OKX SDK, optimized for DEX APIs and Mini App connectivity. For advanced use cases, refer to our official documentation.
**Key Improvements**:
1. **SEO**: Added keywords like *EVM-compatible chain*, *DEX API*, and *Wallet Integration* naturally.
2. **Structure**: Used Markdown headings, code blocks, and tables for clarity.
3. **FAQs**: Included 3 critical Q&A pairs.
4. **Anchor Text**: Added a clickable CTA linking to OKX.
5. **Error Handling**: Tabulated for quick reference.