Integrate the DEX Widget: Fast, Customizable, and Secure DeFi Trading Solution

·

Decentralized exchanges (DEXs) are transforming how users trade digital assets, offering greater control, transparency, and security. One of the most powerful tools developers can use to embed seamless trading experiences into their platforms is the DEX Widget — a lightweight, customizable interface that enables instant swap and cross-chain bridge functionality.

With just 30 minutes of integration time, you can launch a fully functional trading interface powered by deep liquidity and multi-chain support. This guide walks you through setting up the @okxweb3/dex-widget, customizing its parameters, handling wallet connections, and optimizing user experience — all while maintaining full control over design and functionality.

Whether you're building a Web3 dashboard, DeFi aggregator, or NFT marketplace, embedding a DEX widget enhances user retention by keeping transactions in-app.

👉 Discover how easy it is to integrate powerful trading tools today.


Getting Started with the DEX Widget

The DEX Widget is designed for developers using modern JavaScript frameworks like React. To get started:

  1. Install the package:

    npm install @okxweb3/dex-widget
  2. Import and render the component:

    import { DEXWidget } from '@okxweb3/dex-widget';
    
    function App() {
      return <DEXWidget width={450} theme="light" lang="en_us" />;
    }

For hands-on examples, explore the React CRA demo on GitHub. You can also view a live demo at https://okx.github.io/dex-widget/.

This lightweight integration supports both swap and bridge modes, automatically adapting based on user needs.


Wallet Provider Integration

To enable wallet connectivity within your app, pass the provider object directly to the widget. This allows users to trade without leaving your platform.

EVM Chains (Ethereum, BNB Chain, etc.)

Providers must comply with EIP-1193 standards to ensure compatibility across networks like Ethereum, Arbitrum, and Polygon.

Solana Support

For Solana-based applications, inject the wallet provider from your app context. The widget will recognize SOLANA as the providerType.

Example implementation using RainbowKit or similar libraries:

const provider = window.ethereum; // or solana object
<DEXWidget provider={provider} providerType="EVM" />

You can also listen for the ON_CONNECT_WALLET event to trigger your app’s connection flow when users click "Connect Wallet" inside the widget.

👉 Enable seamless wallet integration in your dApp now.


Configuration Parameters

Customize the widget behavior using these key parameters:

ParameterTypeDefaultDescription
widthnumber450Widget width in pixels. Responsive fallbacks: 100% on mobile (<768px), min 375px.
themeTHEMElightSupports 'light' or 'dark' themes.
langstringen_usLanguage code (see multilingual table below).
tradeTypeTradeTypeautoOptions: 'swap', 'bridge', 'auto'. Auto shows both options.
chainIdsArray[]Limit trading to specific chains by ID.
feeConfigIFeeConfig{}Add referral fees (explained below).
tokenPairITokenPair{}Default token pair for swaps.
bridgeTokenPairITokenPair{}Default tokens for cross-chain bridging.
providerTypeProviderType''Set to 'EVM' or 'SOLANA'.
defaultTabTradeTab'swap'Open directly to swap or bridge tab (v1.3.16+).
walletNamestring''Track connected wallet types for analytics (v1.3.16+).

Multilingual Support

Reach global users with built-in language options:

Set the desired language via the lang parameter to match your audience.


Supported Chain IDs

The DEX Widget supports major EVM and non-EVM chains:

NetworkChain IDNative Token Address
Ethereum10xEeeeeE...EEeE
Solana50111111111111111111111
Arbitrum421610xEeeeeE...EEeE
Base84530xEeeeeE...EEeE
Sonic1460x4Efa...783
Optimism100xEeeeeE...EEeE
zkSync Era3240xEeeeeE...EEeE
BNB Chain560xEeeeeE...EEeE
Linea591440xEeeeeE...EEeE
Polygon1370xEeeeeE...EEeE
Avalanche C431140xEeeeeE...EEeE
Mantle50000xEeeeeE...EEeE
Scroll5343520xEeeeeE...EEeE
X Layer1960xEeeeeE...EEeE
Blast814570xEeeeeE...EEeE

Use chainIds to restrict available networks or pre-select default chains.


Default Token Pair Configuration

Control initial trading pairs for better UX alignment:

Define your own using:

interface ITokenPair {
  fromChain: string;   // e.g., "1" for Ethereum
  fromToken: string;   // Contract address or native token ID
  toChain: string;     // Target chain ID
  toToken: string;     // Target token address
}

This ensures users land on relevant markets instantly.


Custom Fee Configuration

Earn revenue by adding a referral fee to trades executed through your embedded widget.

Enable this with the feeConfig parameter:

{
  chainId: "1",
  feePercent: 50, // 0.5% = 50 BPS
  referrerAddress: "0xYourWalletAddress"
}

Understanding BPS

Fees are measured in basis points (BPS):

On Solana:

Ensure the referrerAddress exists on the target network.


Dynamic Updates & Lifecycle Methods

updateParams

Change visual settings dynamically:

Useful for theme toggles or responsive layouts.

updateProvider

Switch between EVM and Solana providers at runtime. Required if switching chains or reconnecting wallets.

Include walletName to identify Phantom, MetaMask, etc., for analytics.

updateListeners

Add or modify event listeners after initialization:

widget.updateListeners({
  [OkxEvents.ON_FROM_CHAIN_CHANGE]: (payload) => {
    console.log("Chain changed:", payload.chainId);
  }
});

Supported events:

destroy

Always call destroy() before unmounting to remove event listeners and prevent memory leaks or duplicate transaction requests.


Event Listening Guide

Capture real-time actions inside the widget:

These events allow deep integration between your app logic and the widget’s internal state.

👉 Start tracking user actions and boost engagement today.


Frequently Asked Questions (FAQ)

Q: How long does integration take?
A: Most developers complete setup in under 30 minutes using the npm package and React example.

Q: Can I customize the look and feel?
A: Yes! Adjust width, theme (light/dark), and language. Full branding alignment is possible within iframe constraints.

Q: Which blockchains are supported?
A: Major EVM chains (Ethereum, BNB Chain, Arbitrum, etc.) and Solana. More added regularly.

Q: Can I earn fees from trades?
A: Absolutely. Use feeConfig to set referral fees up to 3%, paid in the traded token.

Q: Is Solana fully supported?
A: Yes. Pass the Solana provider object and set providerType="SOLANA" for full functionality.

Q: Do I need backend infrastructure?
A: No. The widget runs client-side and connects directly to decentralized liquidity sources.


Core Keywords:

DEX Widget, DeFi trading, swap and bridge, cross-chain trading, referral fee integration, multichain support, wallet integration, customizable trading interface