The DZap SDK provides functionality to request trade quotes, as well as to execute them. This guide will walk you through the process of making a request using getTradeQuotes.

How to Request Trade Quotes

To get started, here is a simple example of how to request quotes to bridge and swap 1 USDC on Arbitrum to ETH on Base.
import { DZapClient } from "@dzap/sdk";

const dZap = DZapClient.getInstance();

const quotesRequest: TradeQuotesRequest = {
  integratorId: "your-integrator-id", // Your unique integrator ID (use "dzap" for testing)
  fromChain: 42161, // Arbitrum
  data: [
    {
      amount: "1000000", // 1 USDC (6 decimals)
      srcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC on Arbitrum
      destToken: "0x4200000000000000000000000000000000000006", // WETH on Base
      toChain: 8453, // Base Chain
      slippage: 1, // 1% slippage
    },
  ],
  account: userAccount, // User's wallet address (optional)
};

const result = await dZap.getTradeQuotes(quotesRequest);
const quotes = result.quotes;
When you request quotes, you receive an object containing the essential information to determine which route to take for a swap or bridging transfer. At this stage, transaction data is not included and must be requested separately using buildTradeTransaction.

Trade Quotes Request Parameters

The getTradeQuotes function expects a TradeQuotesRequest object, which specifies a desired trade and includes all the information needed to calculate the most efficient routes.

Request Parameters

ParameterTypeRequiredDescription
integratorIdstringyesYour unique integrator identifier (e.g. “dzap”)
fromChainnumberyesThe ID of the source chain (e.g., Ethereum mainnet is 1)
dataTradeQuotesRequestData[]yesArray of trade request data objects
accountstringnoUser’s wallet address for the trade (optional)
filterQuoteFilternoFilter type for quote results (default is “all”)
allowedSourcesstring[]noList of allowed providers for the trade (optional)

TradeQuotesRequestData Parameters

ParameterTypeRequiredDescription
amountstringyesThe amount to be transferred from the source chain, specified in the smallest unit of the token
srcTokenstringyesThe contract address of the token on the source chain
destTokenstringyesThe contract address of the token on the destination chain
toChainnumberyesThe ID of the destination chain
slippagenumberyesThe slippage tolerance as a percentage (e.g., 1 for 1%)

Quote Filter Options

You can filter quotes based on different criteria:
  • all - Returns all available quotes. This is the default option and provides the fastest response time.
  • best - Return only the best quote
  • fastest - Return the fastest execution time quote (for bridge operations)
const quotesRequest: TradeQuotesRequest = {
  integratorId: "your-integrator-id",
  fromChain: 42161,
  data: [
    {
      amount: "1000000",
      srcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
      destToken: "0x4200000000000000000000000000000000000006",
      toChain: 8453,
      slippage: 1,
    },
  ],
  account: userAccount,
  filter: "best", // Only return the best quote
};

Advanced Quote Configuration

For applications requiring fine-tuned control over quote optimization, the SDK provides advanced configuration options:

Advanced Parameters

ParameterTypeRequiredDescription
timingStrategyTimingStrategynoFine-tune quote optimization timing behavior
disablePricingbooleannoSkip pricing calculations for faster response times

TimingStrategy Configuration

The timingStrategy parameter allows fine-grained control over how the SDK optimizes quote collection:

minWaitTimeMs

PropertyTypeDefaultDescription
minWaitTimeMsnumber1000Minimum wait time before returning results. Sets the floor for how long the SDK will wait before returning quotes, ensuring adequate time for providers to respond. Useful when you want to guarantee a minimum collection time for better quote diversity.

maxWaitTimeMs

PropertyTypeDefaultDescription
maxWaitTimeMsnumber5000Maximum wait time for quote optimization. Sets the ceiling for quote collection time. The SDK will stop waiting for additional quotes after this duration, even if more providers might respond. Helps balance quote quality with response time requirements.

subsequentDelayMs

PropertyTypeDefaultDescription
subsequentDelayMsnumber500Delay between subsequent quote requests. Controls the interval between batched quote requests to providers. Lower values may overwhelm providers, while higher values may slow down quote collection. Optimize based on provider response patterns.

preferredResultCount

PropertyTypeDefaultDescription
preferredResultCountnumber3Target number of quote results to collect. The SDK will attempt to gather this many quotes before potentially stopping early (if within timing constraints). Higher values provide more options but may increase response time.

disablePricing Configuration

PropertyTypeDefaultDescription
disablePricingbooleanfalseSkip pricing calculations for faster response times. When enabled, the SDK will skip detailed price impact calculations and USD value conversions, significantly reducing response time. Ideal for high-frequency applications where speed is prioritized over detailed pricing data.

Advanced Configuration Example

const quotesRequest: TradeQuotesRequest = {
  integratorId: "your-integrator-id",
  fromChain: 42161,
  data: [
    {
      amount: "1000000",
      srcToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
      destToken: "0x4200000000000000000000000000000000000006",
      toChain: 8453,
      slippage: 1,
    },
  ],
  account: userAccount,
  
  // Advanced timing configuration for optimal quote collection
  timingStrategy: {
    minWaitTimeMs: 1500,      // Wait at least 1.5 seconds for provider responses
    maxWaitTimeMs: 4000,      // Don't wait more than 4 seconds total
    subsequentDelayMs: 300,   // 300ms between provider batches
    preferredResultCount: 5,  // Try to collect 5 different quotes
  },
  
  // Disable pricing for faster response in high-frequency scenarios
  disablePricing: true,
};

TypeScript Type Definition

type TimingStrategy = Partial<{
  minWaitTimeMs: number;        // Minimum wait time before returning results
  maxWaitTimeMs: number;        // Maximum wait time for quote optimization
  subsequentDelayMs: number;    // Delay between subsequent quote requests
  preferredResultCount: number; // Target number of quote results to collect
}>;

## Understanding the Response

The response contains detailed information about available routes:

```typescript
type TradeQuotesResponse = {
  [pair: string]: {
    recommendedSource: string;
    quoteRates: TradeQuotesByProviderId;
    tokensWithoutPrice: Record<number, string[]>; // Tokens without price data by chain ID
  };
};

Key Response Fields

  • pair - Unique identifier for the trade pair (e.g., 42161_0xaf88d065e77c8cC2239327C5EDb3A432268e5831_8453_0x42000000000000000000000000000000000000006). Can be generated using getTokensPairKey.
  • recommendedSource - The provider ID of the recommended route
  • quoteRates - Object containing detailed quotes for each provider
  • tokensWithoutPrice - Tokens that don’t have price data available

Working with Quote Results

const result = await dZap.getTradeQuotes(quotesRequest);

// Get the pair key (usually the first and only one for single trades)
const pairKey = Object.keys(result)[0];
const pairData = result[pairKey];

// Get the recommended route
const recommendedProvider = pairData.recommendedSource;
const recommendedQuote = pairData.quoteRates?.[recommendedProvider];

if (recommendedQuote) {
  console.log("Best route details:");
  console.log("Source amount:", recommendedQuote.srcAmount);
  console.log("Destination amount:", recommendedQuote.destAmount);
  console.log("Provider:", recommendedQuote.providerDetails.name);
  console.log("Estimated duration:", recommendedQuote.duration);
  console.log("Price impact:", recommendedQuote.priceImpactPercent);
}

Next Steps

Once you have received quotes, you can proceed to:
  1. Execute the transaction on the blockchain
  2. Track the status of your trade
Before executing trades, tokens typically require approval to allow the DZap contracts to spend them on your behalf. Learn more about gas-optimized approval mechanisms in the Approval Mechanisms section.