V3 QuoterV2
The QuoterV2 contract allows getting the expected amount out or amount in for a given V3 swap without executing the swap. It simulates the swap logic on-chain to return accurate quotes.
These functions are not gas efficient and should not be called on-chain. Instead, use them via eth_call (static call) from off-chain code. For on-chain swap execution, use the V3 Router or Universal Router.
Key Functions
Returns the expected output amount for a single-pool exact input swap.
function quoteExactInputSingle(
QuoteExactInputSingleParams memory params
) public override returns (
uint256 amountOut,
uint160 sqrtPriceX96After,
uint32 initializedTicksCrossed,
uint256 gasEstimate
);
Parameters (struct QuoteExactInputSingleParams):
| Parameter | Type | Description |
|---|
tokenIn | address | Input token address |
tokenOut | address | Output token address |
amountIn | uint256 | The desired input amount |
fee | uint24 | Pool fee tier (100, 500, 3000, or 10000) |
sqrtPriceLimitX96 | uint160 | Price limit (0 for no limit) |
Returns:
| Return | Type | Description |
|---|
amountOut | uint256 | The expected output amount |
sqrtPriceX96After | uint160 | The pool price after the swap |
initializedTicksCrossed | uint32 | Number of initialized ticks crossed |
gasEstimate | uint256 | Estimated gas cost of the swap |
Returns the expected output amount for a multi-hop exact input swap.
function quoteExactInput(
bytes memory path,
uint256 amountIn
) public override returns (
uint256 amountOut,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate
);
| Parameter | Type | Description |
|---|
path | bytes | Encoded swap path (token addresses and fees) |
amountIn | uint256 | The desired input amount |
Returns:
| Return | Type | Description |
|---|
amountOut | uint256 | The expected output amount |
sqrtPriceX96AfterList | uint160[] | Pool prices after each hop |
initializedTicksCrossedList | uint32[] | Ticks crossed per hop |
gasEstimate | uint256 | Total estimated gas cost |
quoteExactOutputSingle
Returns the required input amount for a single-pool exact output swap.
function quoteExactOutputSingle(
QuoteExactOutputSingleParams memory params
) public override returns (
uint256 amountIn,
uint160 sqrtPriceX96After,
uint32 initializedTicksCrossed,
uint256 gasEstimate
);
Parameters (struct QuoteExactOutputSingleParams):
| Parameter | Type | Description |
|---|
tokenIn | address | Input token address |
tokenOut | address | Output token address |
amount | uint256 | The desired output amount |
fee | uint24 | Pool fee tier |
sqrtPriceLimitX96 | uint160 | Price limit (0 for no limit) |
quoteExactOutput
Returns the required input amount for a multi-hop exact output swap.
function quoteExactOutput(
bytes memory path,
uint256 amountOut
) public override returns (
uint256 amountIn,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksCrossedList,
uint256 gasEstimate
);
| Parameter | Type | Description |
|---|
path | bytes | Encoded swap path (reversed for exact output) |
amountOut | uint256 | The desired output amount |
Callback
uniswapV3SwapCallback
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes data
) external view override;
Called by the pool during quote simulation. This is an internal mechanism — you do not need to call this directly.
| Parameter | Type | Description |
|---|
amount0Delta | int256 | Amount of token0 sent (negative) or received (positive) by the pool |
amount1Delta | int256 | Amount of token1 sent (negative) or received (positive) by the pool |
data | bytes | Callback data passed through from the swap call |
ABI
[
"function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96)) returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
"function quoteExactInput(bytes path, uint256 amountIn) returns (uint256 amountOut, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)",
"function quoteExactOutputSingle((address tokenIn, address tokenOut, uint256 amount, uint24 fee, uint160 sqrtPriceLimitX96)) returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
"function quoteExactOutput(bytes path, uint256 amountOut) returns (uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)"
]
Example: Get a Quote
const QUOTER_ABI = [
'function quoteExactInputSingle((address,address,uint256,uint24,uint160)) returns (uint256,uint160,uint32,uint256)',
];
const quoter = new ethers.Contract(QUOTER_V2_ADDRESS, QUOTER_ABI, provider);
// Quote: how much tokenOut for 1 tokenIn via the 0.3% pool?
const [amountOut, sqrtPriceAfter, ticksCrossed, gasEstimate] =
await quoter.quoteExactInputSingle.staticCall({
tokenIn: '0xTokenA',
tokenOut: '0xTokenB',
amountIn: ethers.parseEther('1'),
fee: 3000,
sqrtPriceLimitX96: 0,
});
console.log(`Expected output: ${ethers.formatEther(amountOut)}`);
console.log(`Gas estimate: ${gasEstimate}`);
Always use staticCall (ethers v6) or callStatic (ethers v5) — these functions revert if called as regular transactions.