get_swap_quote
Generate executable token swap quotes with transaction data for DeFi trading across multiple blockchains.
Instructions
Get executable quote with transaction data for a token swap
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | Yes | Blockchain ID (e.g., 1 for Ethereum) | |
| buyToken | Yes | Contract address of token to buy | |
| sellToken | Yes | Contract address of token to sell | |
| sellAmount | Yes | Amount of sellToken in base units | |
| taker | No | Address executing the trade (optional, uses USER_ADDRESS from env) | |
| slippageBps | No | Maximum acceptable slippage in basis points (optional, default: 100) |
Implementation Reference
- src/services/agService.js:30-49 (helper)Helper function in AgService that performs the actual HTTP request to the aggregator API endpoint /api/swap/quote to fetch the swap quote data.
async getSwapQuote(params) { try { const queryParams = new URLSearchParams(params); const response = await fetch(`${this.baseUrl}/api/swap/quote?${queryParams}`); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'API request failed'); } return data.data; } catch (error) { throw new Error(`Failed to get swap quote: ${error.message}`); } }