Skip to main content
Swap one token for another on the same chain. DZap gets quotes from the DEXs and aggregators it supports, recommends a route, and builds the transaction for it. You sign it with your own wallet, then check its status until the swap settles. Pick EVM or Solana in any tab, and the rest of the page switches with it.

Setup

This example swaps 100 USDC for WETH on Arbitrum. The SDK signs and sends transactions with walletClient, a viem wallet client built from the private key in the PRIVATE_KEY environment variable. In a browser app, pass the connected wallet’s client instead. No API key is needed.Amounts are whole numbers in the token’s smallest unit, written as strings. USDC has 6 decimals, so 100 USDC is 100000000.

Steps

1

Quote

getTradeQuotes asks the DEXs and aggregators DZap supports for a price. The response holds one entry per token pair, read into pair: its quoteRates lists every route that can fill the swap, and recommendedSource names the one DZap recommends. slippage: 1 accepts up to 1% less WETH than quoted; below that, the swap fails.
2

Approve

The DZap router, the contract that performs the swap, needs your permission to move your USDC. getAllowance reads how much it may spend now; if that’s less than the swap amount, approve() sends an approval for exactly that amount, which costs a little ETH in gas.
Permit2 vs EIP-2612 vs plain approvals, and gasless permit signing, are in Check allowance and Approval mechanisms.
3

Build & send

trade() asks DZap to build the transaction for the recommended route, then signs it with your wallet and sends it. DZap simulates it first: if it would fail, for example because your USDC balance or allowance is too low, nothing is sent and result says why. recipient gets the WETH and refundee any refund; gasless: false means you pay the gas.
4

Status

trade() returns as soon as the transaction is sent, so check getTradeTxnStatus every 15 seconds until the status leaves PENDING; COMPLETED means the swap went through. DZap answers 404 until it has picked up the transaction, and 429 once the keyless limit of 5 requests a minute is used up, so the catch skips only those two and rethrows anything else. The loop gives up after 5 minutes, and the check after it throws unless the status is COMPLETED.

End-to-end

API usage

The same flow over REST. Non-EVM chains build a chain-specific transaction you sign locally, then submit via Broadcast.
Approve the DZap router for the USDC first, then sign and send the transaction from the build response with your own wallet. Full reference: Quote, Build Tx, Status.

What can go wrong

  • No route: pair.quoteRates is empty; pair.unavailableRoutes says why each provider declined.
  • The build fails: trade() returns an error and buildTradeTxn throws. The error’s action says what to fix: ADD_FUNDS, INCREASE_ALLOWANCE, or TRY_ANOTHER_ROUTE (quote again).
  • expired from broadcastTradeTx: build and sign again right away.
  • Not completed: no status: DZap never returned a status, usually because the transaction failed on-chain. Check the hash in a block explorer.
  • HTTP 429: without an API key, the trade API allows 5 requests a minute in total, shared by every endpoint, and retryAfter says how many seconds to wait. The status loop skips 429s and polls again.
See Error codes for the full catalog.
Last modified on October 1, 2026