DEX API
Use iFrame

Use iFrame#

Step 1: Domain allowlisting#

In order to avoid cross-chain attacks and ensure the security of our users’ funds, OKX DEX requires all iFrame integrator domains to be allowlisted.

Please contact dex@okx.com if you would like to get your domain whitelisted. We will contact you in 1~3 work days.

Step 2: Adding iFrame to your site#

Example codes#

  1. Swap

Swap ETH for USDT on the Ethereum chain

<iframe
  src="https://www.okx.com/web3/dex-swap#inputChain=1&inputCurrency=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&outputChain=1&outputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7"
/>

Swap ETH for USDT on the Ethereum chain with a fee setting. In this example, 1% of the ETH amount will be sent to referrerAddress and 99% of the ETH amount will be used to execute the swap.

<iframe
    src="https://www.okx.com/web3/dex-swap?inputChain=1&inputCurrency=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&outputChain=1&outputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&referrerAddress=0x6f9ffea7370310cd0f890dfde5e0e061059dcfd9&feePercent=1"
/>
  1. Cross-chain swap

Swap USDT on the Ethereum chain for USDT on the Arbitrum chain.

<iframe
    src="https://www.okx.com/web3/dex-swap#inputChain=1&inputCurrency=0xdac17f958d2ee523a2206206994597c13d831ec7&outputChain=42161&outputCurrency=0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9"
/>
  1. Limit order

Place a limit order to swap WETH for USDC on the Ethereum chain.

<iframe
   src="https://www.okx.com/web3/dex-swap/limit#inputLimitChain=1&inputLimitCurrency=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&outputLimitChain=1&outputLimitCurrency=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
/>

Parameters#

ParameterDescription
inputChainThe source chain ID that inputCurrency belongs to (e.g., 1: Ethereum. See appendix for a full list of supported chains with the corresponding chain IDs.)
inputCurrencyThe contract address of a token to be sold. (e.g., 0xdac17f958d2ee523a2206206994597c13d831ec7)
If the inputCurrency is a blockchain’s native token, check the appendix to get the contract address.
outputChainThe destination chain ID that outputCurrency belongs to. (e.g., 1. See appendix for a full list of supported chains with the corresponding chain IDs.)
outputCurrencyThe contract address of a token to be bought. (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00)
If the outputCurrency is a blockchain’s native token, check the appendix to get the contract address.
referrerAddressThe wallet address to which the fees will be sent. (e.g., 0x6f9ffea7370310cd0f890dfde5e0e061059dcfd9) (optional)
feePercentThe percentage of inputCurrency amount will be sent to the referrer’s address. The rest will be set as the input amount to be sold (optional). Min percentage: 0 Max percentage: 3
(Note: cross-chain swap and limit order can’t set referrerAddress and feePercent)
inputLimitChainThe chain ID that inputLimitCurrency belongs to (e.g., 1. Limit order can support transactions on Ethereum, BNB Chain, OKTC, Polygon, Avalanche C, Fantom, Arbitrum, Optimism chains. See appendix for a full list of chain IDs)
inputLimitCurrencyThe contract address of a token to be sold for the limit order (e.g., 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2)
Native token transactions aren’t supported
outputLimitChainThe chain ID that outputLimitCurrency belongs to (e.g., 1: Ethereum. Limit orders support transactions on Ethereum, BNB Chain, OKTC, Polygon, Avalanche C, Fantom, Arbitrum, and Optimism chains. See appendix for a full list of chain IDs)
outputLimitCurrencyThe contract address of a token to be bought for the limit order (e.g., 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)
Native token transactions aren’t supported

Appendix#

ChainChain IDNative contract address
Ethereum10xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
zkSync Era3240xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Optimism100xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Polygon1370xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
OKTC660xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Avalanche C431140xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Fantom2500xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Arbitrum421610xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Linea591440xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Conflux eSpace10300xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Base84530xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Mantle50000xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Scroll5343520xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Polygon zkEVM11010xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Ethereum PoW100010xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Stacks5757STX
Solana50111111111111111111111111111111111
Cronos250xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
Tron195T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
SUI7840x2::sui::SUI
Starknet90040x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
Aptos6370x1::aptos_coin::AptosCoin
Metis10880xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE