Skip to main content

Overview

The OKX DEX SDK supports 26+ blockchain networks across EVM-compatible chains and non-EVM networks including Solana and Sui.

Supported Networks

All chains are configured by default in the SDK at /src/okx/api/dex.ts:51-254.

Major EVM Chains

ChainChain IDExplorerFeatures
Ethereum1OKX ExplorerSwap, Quote, Approve, Broadcast
Base8453OKX ExplorerSwap, Quote, Approve, Broadcast
Polygon137OKX ExplorerSwap, Quote, Approve, Broadcast
Sonic146OKX ExplorerSwap, Quote, Approve, Broadcast
Avalanche C-Chain43114OKX ExplorerSwap, Quote, Approve, Broadcast
BSC56OKX ExplorerSwap, Quote, Approve, Broadcast
Arbitrum42161OKX ExplorerSwap, Quote, Approve, Broadcast
Optimism10OKX ExplorerSwap, Quote, Approve, Broadcast

Layer 2 & Scaling Solutions

ChainChain IDExplorerFeatures
Polygon zkEVM1101OKX ExplorerSwap, Quote, Approve, Broadcast
zkSync Era324OKX ExplorerSwap, Quote, Approve, Broadcast
Linea59144OKX ExplorerSwap, Quote, Approve, Broadcast
Scroll534352OKX ExplorerSwap, Quote, Approve, Broadcast
Mantle5000OKX ExplorerSwap, Quote, Approve, Broadcast
Blast81457OKX ExplorerSwap, Quote, Approve, Broadcast
X Layer196OKX ExplorerSwap, Quote, Approve, Broadcast

Other EVM Chains

ChainChain IDExplorerFeatures
Fantom Opera250OKX ExplorerSwap, Quote, Approve, Broadcast
Gnosis100OKX ExplorerSwap, Quote, Approve, Broadcast
Manta Pacific169OKX ExplorerSwap, Quote, Approve, Broadcast
Metis1088OKX ExplorerSwap, Quote, Approve, Broadcast
Cronos25CronoscanSwap, Quote, Approve, Broadcast
Conflux1030Conflux ScanSwap, Quote, Approve, Broadcast
Zeta Chain7000Zeta ExplorerSwap, Quote, Approve, Broadcast
OKT Chain66OKX ExplorerSwap, Quote, Approve, Broadcast

Non-EVM Chains

ChainChain IDExplorerFeatures
Solana501OKX ExplorerSwap, Quote, Broadcast
Sui784OKX ExplorerSwap, Quote, Broadcast
TON607N/AQuote only
TRON195N/AQuote only
Non-EVM chains like Solana and Sui don’t require token approvals due to different transaction models.

Default Chain Configuration

Each chain comes with pre-configured settings:
{
  id: "8453",                    // Chain identifier
  explorer: "https://...",       // Block explorer URL
  defaultSlippage: "0.005",      // 0.5% default slippage
  maxSlippage: "1",              // 100% maximum slippage
  confirmationTimeout: 60000,    // 60 seconds
  maxRetries: 3                  // 3 retry attempts
}

Configuration Fields

FieldTypeDescription
idstringChain ID (matches public chain ID)
explorerstringTransaction explorer base URL
defaultSlippagestringDefault slippage tolerance (0-1 range)
maxSlippagestringMaximum allowed slippage
confirmationTimeoutnumberTransaction confirmation timeout (ms)
maxRetriesnumberMax retry attempts for failed transactions
computeUnitsnumberSolana-specific: compute units (default 300000)

Chain-Specific Examples

Ethereum Mainnet

const quote = await client.dex.getQuote({
  chainIndex: '1',
  fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH
  toTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',   // USDC
  amount: '1000000000000000000',  // 1 ETH
  slippagePercent: '0.005'
});

Base Chain

const swap = await client.dex.executeSwap({
  chainIndex: '8453',
  fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH
  toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',   // USDC
  amount: '100000000000000000',   // 0.1 ETH
  slippagePercent: '0.005',
  userWalletAddress: evmWallet.address
});

Solana

const swap = await client.dex.executeSwap({
  chainIndex: '501',
  fromTokenAddress: 'So11111111111111111111111111111111111111112',  // SOL
  toTokenAddress: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',    // USDC
  amount: '1000000000',  // 1 SOL (9 decimals)
  slippagePercent: '0.005',
  userWalletAddress: solanaWallet.publicKey.toString()
});

Sui

const quote = await client.dex.getQuote({
  chainIndex: '784',
  fromTokenAddress: '0x2::sui::SUI',  // Native SUI
  toTokenAddress: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
  amount: '1000000000',  // 1 SUI (9 decimals)
  slippagePercent: '0.005'
});

Checking Chain Support

Get chain configuration and supported features:
// Get chain information
const chainData = await client.dex.getChainData('8453');

console.log('Chain Name:', chainData.data[0].chainName);
console.log('Router Address:', chainData.data[0].dexTokenApproveAddress);

Response Structure

{
  code: "0",
  msg: "",
  data: [{
    chainIndex: "8453",
    chainName: "Base",
    dexTokenApproveAddress: "0x..."  // Contract address for approvals
  }]
}

Overriding Chain Configuration

Customize settings for specific chains:
const client = new OKXDexClient({
  apiKey: process.env.OKX_API_KEY!,
  secretKey: process.env.OKX_SECRET_KEY!,
  apiPassphrase: process.env.OKX_API_PASSPHRASE!,
  projectId: process.env.OKX_PROJECT_ID!,
  networks: {
    '8453': {  // Override Base configuration
      id: '8453',
      explorer: 'https://basescan.org/tx',
      defaultSlippage: '0.01',        // 1% instead of 0.5%
      maxSlippage: '0.05',            // 5% instead of 100%
      confirmationTimeout: 120000,    // 2 minutes instead of 1
      maxRetries: 5                   // 5 retries instead of 3
    },
    '501': {  // Override Solana configuration
      id: '501',
      explorer: 'https://solscan.io/tx',
      defaultSlippage: '0.01',
      maxSlippage: '0.05',
      computeUnits: 500000,           // Increase compute units
      confirmationTimeout: 90000,
      maxRetries: 5
    }
  }
});
Custom network configurations merge with defaults. Ensure id matches the chain ID you’re overriding.

Getting Available Tokens

Fetch all supported tokens for a specific chain:
// Get tokens for Base chain
const tokens = await client.dex.getTokens('8453');

tokens.data.forEach(token => {
  console.log(`${token.tokenSymbol}: ${token.tokenContractAddress}`);
});

Token Response Structure

{
  code: "0",
  msg: "",
  data: [{
    tokenSymbol: "USDC",
    tokenName: "USD Coin",
    tokenContractAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    decimals: "6",
    tokenLogoUrl: "https://..."
  }]
}

Checking DEX Liquidity

View available DEX sources for a chain:
// Get liquidity sources for Ethereum
const liquidity = await client.dex.getLiquidity('1');

liquidity.data.forEach(dex => {
  console.log(`${dex.name} (ID: ${dex.id})`);
});

Example Output

Uniswap V3 (ID: uniswap-v3)
Curve (ID: curve)
Balancer (ID: balancer)
1inch (ID: 1inch)
SushiSwap (ID: sushiswap)

Chain Status & Monitoring

Monitor chain status before executing trades:
async function isChainHealthy(chainId: string): Promise<boolean> {
  try {
    const chainData = await client.dex.getChainData(chainId);
    return chainData.code === '0' && chainData.data.length > 0;
  } catch (error) {
    console.error(`Chain ${chainId} health check failed:`, error);
    return false;
  }
}

// Use before trading
if (await isChainHealthy('8453')) {
  // Safe to proceed
  const swap = await client.dex.executeSwap({ /* ... */ });
}
Execute operations across multiple chains:
const chains = ['1', '8453', '137', '42161'];  // Ethereum, Base, Polygon, Arbitrum

const quotes = await Promise.all(
  chains.map(chainId => 
    client.dex.getQuote({
      chainIndex: chainId,
      fromTokenAddress: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
      toTokenAddress: '0x...',  // USDC address varies by chain
      amount: '1000000000000000000',
      slippagePercent: '0.005'
    })
  )
);

quotes.forEach((quote, idx) => {
  console.log(`Chain ${chains[idx]}: ${quote.data[0].toTokenAmount} USDC`);
});

Feature Availability

All EVM Chains Support

  • Token quotes via getQuote()
  • Token swaps via executeSwap()
  • Token approvals via executeApproval()
  • Transaction broadcasting via broadcastTransaction()
  • Gas estimation via getGasLimit() and getGasPrice()
  • Transaction simulation via simulateTransaction()

Solana & Sui Support

  • Token quotes via getQuote()
  • Token swaps via executeSwap()
  • Transaction broadcasting via broadcastTransaction()
  • No approval required (different transaction model)

TON & TRON Support

  • Token quotes via getQuote()
  • Swap execution coming soon
For TON and TRON, currently only quote functionality is available. Full swap execution is under development.

Next Steps

Client Initialization

Set up the client for your target chains

Error Handling

Handle chain-specific errors properly

Build docs developers (and LLMs) love