Execute trades seamlessly by building transaction data and sending it with your wallet signer. The SDK handles transaction building, gas estimation, and execution automatically.The
trade method combines transaction building and execution into a single, streamlined operation. This approach simplifies the trading process while maintaining full control over transaction parameters.
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.
Rate Limits: Our API and SDK have rate limits in place to ensure fair usage.
If you need increased rate limits for your application, please reach out to our
team on Telegram.
Trade Execution
Execute a trade using the trade method:Parameters
Thetrade function expects an object with these parameters:
Required Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | TradeBuildTxnRequest | yes | The trade build request containing all trade details |
signer | Signer | WalletClient | yes | Ethers signer or viem wallet client for signing transactions |
txnData | TradeBuildTxnResponse | no | Pre-built transaction data (skips build step if provided) |
TradeBuildTxnRequest Structure
| Parameter | Type | Required | Description |
|---|---|---|---|
fromChain | number | yes | Source chain ID |
sender | HexString | yes | Wallet address sending the transaction |
refundee | HexString | yes | Address to receive refunds |
data | TradeBuildTxnRequestData[] | yes | Array of trade data |
disableEstimation | boolean | no | Disable gas estimation (default: false) |
disablePricing | boolean | no | Disable pricing calculations for faster builds |
publicKey | string | no | Public key for some chains (e.g., Solana) |
TradeBuildTxnRequestData Structure
| Parameter | Type | Required | Description |
|---|---|---|---|
amount | string | yes | Amount to trade (in token units) |
srcToken | string | yes | Source token address |
destToken | string | yes | Destination token address |
toChain | number | yes | Destination chain ID |
protocol | string | yes | Protocol identifier from quotes |
recipient | string | yes | Address to receive destination tokens |
slippage | number | yes | Slippage tolerance percentage |
additionalInfo | AdditionalInfo | no | Additional route-specific data |
permitData | string | no | Pre-signed permit data |
Complete Example with Quotes and Approvals
Here’s a full example that gets quotes, handles approvals, and executes a trade:Best Practices
- Always validate balances before execution
- Check allowances and execute approvals if needed
- Implement proper error handling with retry logic
- Use appropriate slippage settings based on market conditions
- Monitor transaction status for cross-chain trades
Next Steps
After executing trades:- Track the trade status to monitor progress
Always ensure users have sufficient balance for both the trade amount and gas
fees before execution.