Swapping - Fixed Output
SwapExactTokensForTokens - Useful when the user wants a fixed input amount and a variable output amount. You’ll get a quote before executing the swap to ensure you agree with the variable output amount.
Decide the exact input amountIn
For the fixed-input flow we pick how much AUSD (token0) we’re willing to spend and convert that to raw units with the token’s decimals.
Why?
swapExactTokensForTokens will debit precisely this amount of AUSD; the CTK you receive can only go up from the quote you accept next.
Getting the quote for AmountOutMin
With amountIn fixed, get a quote from the pair to know how much CTK (token 1) you’ll get.
Interpretation:
-
1000 AUSDwill return →999.8 CTKat the current price (fee included).You’ll pass this value as a floor; if the final output is lower the swap reverts with
InsufficientOutputAmount.
Approve the allowance
AgoraStableSwapPair cannot pull AUSD from your wallet unless the ERC-20 allowance is set first. We grant the pair permission to spend up to amountIn AUSD, and—as a best-practice—simulate the transaction before broadcasting it
Swapping tokens
With allowance set, we trigger the atomic swap. The swap call will be swapExactTokensForTokens, and it will take the following args:
Checking the explorer allows us to see that the transaction was executed correctly and now we can expect to have 999.8 token1(CTK) in our wallet balance.

For the full example, please refer to our examples repository

