Overview
Before executing a same-chain swap, you can get a detailed estimation to preview:- Expected output token amount
- Minimum output amount (accounting for slippage)
- Transaction fees and gas costs
- Recommended slippage settings
Getting an estimation
Use the estimation endpoint to preview swap details without creating a full transaction:The estimation endpoint doesn’t require
tokenOutRecipient or senderAddress, making it perfect for preview purposes.Estimation parameters
Required parameters
- chainId - The blockchain network ID
- tokenIn - Input token address
- tokenInAmount - Amount to swap in atomic units
- tokenOut - Output token address
Optional parameters
- slippage - Slippage tolerance (default:
"auto") - affiliateFeePercent - Affiliate fee percentage
- affiliateFeeRecipient - Address to receive affiliate fees
Understanding the response
The estimation response contains detailed information about your swap:Response fields explained
Token information
tokenIn - Details about the input token:amount- Exact amount being swapped (in atomic units)decimals- Number of decimals for the tokensymbol- Token symbol (e.g., “USDC”)
amount- Expected amount you’ll receive (in atomic units)minAmount- Minimum amount guaranteed (accounting for slippage)decimals- Number of decimals for the tokensymbol- Token symbol (e.g., “MATIC”)
Slippage values
- slippage - The slippage tolerance applied to this swap (as a decimal, e.g., 0.005 = 0.5%)
- recommendedSlippage - The API’s recommended slippage based on current market conditions
Fee breakdown
TheestimatedTransactionFee object provides detailed gas cost information:
- total - Total estimated fee in the native token (in atomic units)
- gasLimit - Maximum gas units the transaction can use
- gasPrice - Gas price in wei (for legacy transactions)
- baseFee - Base fee per gas (EIP-1559)
- maxFeePerGas - Maximum fee you’re willing to pay per gas unit
- maxPriorityFeePerGas - Maximum priority fee (tip to miners)
- txFee - Base transaction fee
- priorityFee - Additional priority fee
Example: Displaying estimates to users
Here’s how you might format estimation data for display:Complete estimation example
Here’s a complete example that gets an estimation and displays all relevant information:src/scripts/same-chain/estimation/estimation-example.ts:1
API endpoint
The estimation function calls the deBridge API endpoint:Query parameters
chainId- Chain ID (e.g., “137”)tokenIn- Input token addresstokenInAmount- Amount in atomic unitstokenOut- Output token addressslippage- Slippage tolerance (optional, default: “auto”)affiliateFeePercent- Affiliate fee percentage (optional)affiliateFeeRecipient- Affiliate fee recipient address (optional)
When to use estimations
Use the estimation endpoint to:Preview swaps
Show users expected amounts before they confirm
Compare rates
Compare output amounts for different input amounts
Check feasibility
Verify a swap is possible before attempting it
Calculate costs
Determine total costs including fees and slippage
Estimation vs. transaction creation
The main difference between estimation and transaction creation:| Feature | Estimation | Transaction |
|---|---|---|
| Returns transaction data | No | Yes |
| Requires recipient address | No | Yes |
| Requires sender address | No | Yes |
| Can be executed | No | Yes |
| Use case | Preview/analysis | Execution |
Next steps
Execute token swaps
Learn how to create and execute swap transactions with complete code examples