Skip to main content

Method Signature

async getCrossChainQuote(params: CrossChainQuoteParams): Promise<APIResponse<any>>
Retrieves a quote for swapping tokens across different blockchain networks. This method validates slippage parameters and returns routing information, estimated gas fees, and expected amounts.

Parameters

fromChainIndex
string
required
Source chain index identifier (e.g., “1” for Ethereum, “501” for Solana)
toChainIndex
string
required
Destination chain index identifier
fromChainId
string
required
Source chain ID (e.g., “1” for Ethereum mainnet)
toChainId
string
required
Destination chain ID
fromTokenAddress
string
required
Contract address of the token to swap from
toTokenAddress
string
required
Contract address of the token to swap to
amount
string
required
Amount to swap in the smallest unit (e.g., wei for ETH)
slippagePercent
string
required
Maximum acceptable slippage as a decimal (e.g., “0.005” for 0.5%). Must be between 0.002 (0.2%) and 0.5 (50%)
sort
string
Sort order for bridge options (e.g., “cost”, “time”)
dexIds
string
Comma-separated list of DEX IDs to include in routing
allowBridge
string
Comma-separated list of bridge IDs to allow
denyBridge
string
Comma-separated list of bridge IDs to exclude
priceImpactProtectionPercentage
string
Maximum acceptable price impact percentage

Response

code
string
Response code (“0” indicates success)
msg
string
Response message
data
array
Array of quote results
routerResult
object
Routing information for the swap
fromTokenAmount
string
Amount of source tokens to be swapped
toTokenAmount
string
Expected amount of destination tokens to receive
estimateGasFee
string
Estimated gas fee for the transaction
priceImpactPercent
string
Expected price impact as a percentage
tradeFee
string
Trading fee amount

Code Example

import { OKXDexSDK } from '@okxweb3/dex-sdk';

const sdk = new OKXDexSDK({
  apiKey: 'your-api-key',
  secretKey: 'your-secret-key',
  apiPassphrase: 'your-passphrase',
  projectId: 'your-project-id'
});

// Get a quote for bridging USDC from Ethereum to Arbitrum
const quote = await sdk.bridge.getCrossChainQuote({
  fromChainIndex: '1',        // Ethereum
  toChainIndex: '42161',      // Arbitrum
  fromChainId: '1',
  toChainId: '42161',
  fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
  toTokenAddress: '0xFF970a61A04b1cA14834A43f5dE4533eBDDB5CC8',   // USDC on Arbitrum
  amount: '1000000000',       // 1000 USDC (6 decimals)
  slippagePercent: '0.005'    // 0.5% slippage
});

console.log('Expected output:', quote.data[0].routerResult.toTokenAmount);
console.log('Estimated gas:', quote.data[0].routerResult.estimateGasFee);

Error Handling

The method validates slippage parameters and throws an error if slippage is outside the acceptable range:
try {
  const quote = await sdk.bridge.getCrossChainQuote(params);
} catch (error) {
  if (error.message.includes('Slippage must be between')) {
    console.error('Invalid slippage value');
  }
}

Validation Rules

  • Slippage must be between 0.002 (0.2%) and 0.5 (50%)
  • All required chain and token parameters must be provided
  • Amount must be specified in the token’s smallest unit

Build docs developers (and LLMs) love