UI Integration for EVM-Compatible Chains with OKX Connect

·

Integrating wallet connectivity into decentralized applications (dApps) is a critical step in delivering seamless user experiences on blockchain platforms. For developers building on EVM-compatible chains, OKX Connect offers a robust, developer-friendly SDK that simplifies wallet integration while supporting advanced features like multi-chain connectivity, transaction signing, and customizable UI behavior.

To get started, ensure your OKX App is updated to version 6.90.1 or later, enabling full access to the latest OKX Connect capabilities.


Installing OKX Connect via npm

The easiest way to integrate OKX Connect into your dApp is through npm:

npm install @okxconnect/connect

This lightweight package provides all necessary tools for initializing sessions, managing connections, and handling transactions across EVM-compatible networks.


Initializing the SDK

Before connecting to a wallet, you must initialize the OKX Connect interface with configuration options tailored to your application’s needs.

Key Initialization Parameters

👉 Discover how easy it is to integrate secure, multi-chain wallet access into your dApp.

import { OKXUniversalConnectUI } from '@okxconnect/connect';

const okxConnect = new OKXUniversalConnectUI({
  dappMetaData: {
    name: 'My DeFi Dashboard',
    icon: 'https://mydapp.com/icon.png'
  },
  actionsConfiguration: {
    modals: 'all',
    returnStrategy: 'mydapp://return',
    tmaReturnUrl: 'back'
  },
  uiPreferences: {
    theme: THEME.LIGHT,
    language: 'en_US'
  },
  restoreConnection: true
});

Returns: An instance of OKXUniversalConnectUI ready for connection workflows.


Connecting to a Wallet

Establishing a wallet connection grants your dApp access to the user’s address and transaction-signing capabilities.

Request Parameters

⚠️ If any required chain in namespaces isn't supported by the wallet, the connection will be rejected.

Returns a Promise resolving to:


Connect and Sign in One Step

You can initiate both connection and data signing simultaneously using openModalAndSign.

Extended Parameters

Includes all connection fields plus:

Upon success, the event 'connect_signResponse' returns the signature.

👉 See how top dApps streamline onboarding with one-click wallet connect and sign flows.


Check Wallet Connection Status

Determine if a wallet is currently connected:

const isConnected = okxConnect.isConnected();

Returns: Boolean value indicating active session status.

Useful for conditional rendering and protecting sensitive actions behind authentication checks.


Prepare and Send Transactions

Use requestArguments to send signing requests or execute transactions.

Parameters

For full details on response formats, refer to EVM-compatible transaction handling documentation.


Using Custom RPC Endpoints

When default methods are insufficient, configure custom RPCs via rpcMap during connection:

rpcMap: {
  'eip155:1': 'https://eth-mainnet.my-custom-rpc.com',
  'eip155:137': 'https://polygon-rpc.com'
}

This enables interaction with private nodes or enhanced performance layers.

✅ Ensure configured chains are listed in the chains array.

Manage Active Sessions

Get Current Session Info

Retrieve live session data:

const session = okxConnect.getSession();

Returns account, chain, method, and namespace details — ideal for dynamic UI updates.

Set Default Chain

Switch the active network context:

okxConnect.setDefaultChain('eip155:137'); // Switch to Polygon

Ensures correct routing when multiple chains are available.

Disconnect Wallet

Terminate the current session cleanly:

await okxConnect.disconnect();

Clears local state and revokes dApp permissions securely.


Customize UI Settings

Update theme or language dynamically:

okxConnect.setTheme(THEME.DARK);
okxConnect.setLanguage('zh_CN');

Improves accessibility and aligns with user preferences without requiring reinitialization.


Handle Events and Errors

Supported Events

Listen for real-time updates:

Common Error Codes

CodeMeaning
OKX_CONNECT_ERROR_CODES.UNKNOWN_ERRORUnexpected internal error
ALREADY_CONNECTED_ERRORAttempted duplicate connection
NOT_CONNECTED_ERRORAction requires prior connection
USER_REJECTS_ERRORUser denied request
METHOD_NOT_SUPPORTEDWallet doesn’t support requested method
CHAIN_NOT_SUPPORTEDChain not available in wallet
CONNECTION_ERRORNetwork or protocol failure

Handle these gracefully with user-facing messages and retry logic where appropriate.


FAQ

How do I support custom blockchain networks?

Include your network in optionalNamespaces with proper chain ID and RPC configuration. If the wallet doesn’t recognize it, call wallet_addEthereumChain afterward to prompt addition.

Can I connect without showing popups?

Yes — set modals: [] or 'none' in initialization or request-level configurations to suppress alerts.

Is Telegram Mini Wallet supported?

Absolutely. Use tmaReturnUrl: 'back' to ensure users return to your mini app after signing. Ideal for Web3 experiences within Telegram.

What happens if a user rejects a transaction?

The promise rejects with USER_REJECTS_ERROR. You should catch this and inform the user without retrying automatically.

Does OKX Connect support non-EVM chains?

Currently, only EVM-compatible chains are supported via the EIP-155 namespace. Support for other ecosystems may be expanded in future versions.

Can I restore a previous session automatically?

Yes — set restoreConnection: true during initialization to resume existing sessions on page reload or app restart.


👉 Start building smarter, faster dApps with seamless wallet integration today.