9bc85d
Choose a swap mode by what the trade must fix
Exact input vs exact output swap difference comes down to which side is fixed: spend a set amount and protect minimum output, or target output and cap maximum input.
The Hashbeam Desk··4 min read

Swap mode sets which side of a trade stays fixed and which side can move within a limit. Exact input fixes the amount sent into the route; exact output fixes the amount the route must deliver.
That choice determines how slippage protection applies. With exact input, the output can fall, but the transaction reverts if it falls below amountOutMinimum. With exact output, the input can rise, but the transaction reverts if it exceeds amountInMaximum.
A quote is still an estimate based on the route and pool state when it is requested. For a same-chain trade across several liquidity sources, KyberSwap can help find a route, alongside a best price swap comparison. Its routes endpoint takes amountIn, so its aggregator quotes are framed as exact input.
Exact input fixes spend; exact output fixes receipt
Exact input protects the amount you spend and sets a floor on what you receive. Exact output protects the amount you receive and sets a ceiling on what you spend.
In an exact-input swap, the router takes a specified input amount through the chosen route. Pool prices, fees and route composition determine the output. The caller supplies amountOutMinimum; if the route would deliver less at execution, the swap reverts. The user can receive more than the minimum, but cannot accept less in that transaction.
In an exact-output swap, the router starts from the required output and works backwards through the route to calculate the input needed at each hop. The caller supplies amountInMaximum. If execution needs more than that cap, the swap reverts. The actual input may be below the cap, depending on pool state when the transaction executes.
The Uniswap v2 Router exposes this distinction through swapExactTokensForTokens and swapTokensForExactTokens. Uniswap v3 SwapRouter exposes exactInput and exactOutput, using amountOutMinimum and amountInMaximum for the corresponding limits. The names differ, but the risk boundary is the same: exact input risks receiving less; exact output risks spending more.
Consider an illustrative repayment: a wallet owes 1,000 USDC on the same chain and needs to acquire that exact amount of USDC. Exact output fits because it targets the debt amount and caps how much of the source token may be spent. The quote may indicate one input amount, but the transaction can require more if execution conditions move. The maximum must cover that allowed movement.
Now consider an illustrative sale of a full token balance. Exact input fits because the wallet is selling a known amount and can set the minimum acceptable proceeds. If the route cannot meet that floor when the transaction executes, it reverts instead of selling below the bound.
Exact output needs headroom in balance and approval
Exact output requires the wallet balance and token approval to cover amountInMaximum, not merely the quoted input. The quoted input is the estimate for the requested output; the maximum is the contract’s spending limit under the chosen slippage bound.
Suppose the quote says a repayment will cost 980 units of the input token, and the caller permits movement up to a higher cap. The wallet must hold at least that cap, and the router must have approval for at least that cap. If either covers only 980 while execution needs more, the transfer or allowance check fails and the swap reverts, even if the extra amount would remain under the specified maximum.
The maximum is a ceiling, not an instruction to spend the whole amount. The router calculates the input required for the target output and uses that amount, up to the cap. Any portion of the cap it does not need is not taken from the wallet. Set the cap deliberately: too low and the transaction may revert after the quote changes; too high and the transaction permits more spend than intended.
Related questions
What happens to leftover input in an exact-output swap?
Leftover input stays with the wallet when the swap needs less than the approved maximum. The maximum bounds what the router may spend; it is not a prepayment of the full cap. The swap still reverts if the required input exceeds that cap.
Do fee-on-transfer tokens work with exact output?
Fee-on-transfer tokens can make exact output incompatible with a route because the amount received by a pool may be lower than the amount transferred. That breaks the router’s calculation of the input required to deliver a fixed output. Check the token and router behavior before relying on exact output for such a route; exact input is generally the more workable mode when transfer fees make received amounts variable.