Swapping - Fixed Input
If you want to run this example, be sure that you have followed the steps here to configure your Wallet Client.
SwapExactTokensForTokens - Provide a fixed number of tokens you want to swap and receive the number of tokens that would result from that swap.
You’ll still get a quote before executing the swap to ensure you agree with the variable output amount.
Calculate the exact input (amountIn)
For the fixed-input flow we pick how much AUSD we’re willing to spend and convert that to raw units with the token’s decimals.
We’ll be using the getTokenDecimal function to do this.
It’s also important to remember our swapPath example showing that AUSD is token1 in the pair.
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
Now that we’ve defined the amountIn, we can get a quote from the pair to know how much CTK (token0) you’ll get.
Furthermore we’ll actually use the swapPath defined here to execute this function.
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
InsufficientOutputAmounterror message.
Approve the allowance
AgoraStableSwapPair cannot pull AUSD from your wallet unless the ERC-20 allowance is set.
This means we need to 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 use swapExactTokensForTokens, and it will take the following args:
If you want, you can choose to open the Sepolia Explorer and wait for it to process.
No matter what, if the transaction is successfully executed, we can expect to have 999.8 token0(CTK) in the destination wallet’s balance.
For the full example, please refer to our examples repository

