SDK Guide for EVM-Compatible Chains: Connecting Apps & Mini Wallets to Web3

·

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

Returns


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

Returns


Checking Wallet Connection Status

Verify if a wallet is currently linked:

const isConnected = okxUniversalProvider.isConnected();
// Returns: boolean

Transaction Preparation

Execute wallet requests like signing or sending transactions:

await okxUniversalProvider.request({
  method: "eth_sendTransaction",
  params: [transactionParams],
  chain: "eip155:1"
});

Supported Methods


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 default

Disconnecting 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

CodeDescription
UNKNOWN_ERRORUnexpected failure
USER_REJECTS_ERRORUser declined action
CHAIN_NOT_SUPPORTEDUnavailable chain ID
CONNECTION_ERRORSession 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.

👉 Get real-time API support