Using the Quoter
Overview
Basic Quoting
Quote Exact Input (Single Hop)
async function quoteExactInputSingle(tokenIn, tokenOut, fee, amountIn) {
// IMPORTANT: Use callStatic for view-like behavior
// IQuoterV2 uses struct parameters
const [amountOut, sqrtPriceX96After, ticksCrossed, gasEstimate] =
await quoter.callStatic.quoteExactInputSingle({
tokenIn,
tokenOut,
amountIn,
fee,
sqrtPriceLimitX96: 0
});
return {
amountOut,
priceImpact: calculatePriceImpact(amountIn, amountOut, sqrtPriceX96After),
ticksCrossed,
gasEstimate
};
}
// Usage
const quote = await quoteExactInputSingle(
WVC,
USDT,
3000,
ethers.utils.parseEther('1')
);
console.log('Expected output:', ethers.utils.formatUnits(quote.amountOut, 6), 'USDT');Quote Exact Output (Single Hop)
Multi-Hop Quoting
Path Encoding
Quote Multi-Hop Exact Input
Quote Multi-Hop Exact Output
Route Comparison
Find Best Route
Compare Gas Costs
Price Impact Calculation
Calculate Price Impact
Warning Thresholds
Building a Quote Interface
Full Quote Function
React Hook Example
Error Handling
Caching Quotes
Best Practices
Related
Last updated