What Does a Swap Router Contract Do in a DEX Trade?
A swap router contract pulls approved tokens, routes them through liquidity pools and sends output only when your minimum and deadline conditions pass.
The Aeterna Sol Editors

A swap router contract can route one trade through several liquidity pools and send the output to your recipient only if it meets your minimum; pools provide the liquidity, while the router handles the route and trade limits.
What do you pass to a swap router?
You pass five key values to a Uniswap V2-style router: amountIn, amountOutMin, path, to and deadline. Together, they specify the tokens, route, recipient and limits for the trade.
amountIn is how many input tokens you want to swap. amountOutMin is the least output you will accept. The router reverts if the trade produces less, so this value sets a limit against price movement while your transaction is pending.
path is an ordered list of token addresses. A direct swap has two addresses: the input token and output token. A route through an intermediate token has at least three. to is the address that receives the final tokens, and deadline is the latest time the transaction may execute.
SunSwap is a decentralized exchange on TRON where you can swap TRC-20 tokens through liquidity pools. If you are weighing where to trade, read about how SunSwap compares with other DEXs.
How does the router execute the trade?
The router uses your token approval to pull the input, sends it into the first pool, then directs each pool’s output into the next pool along the path. It checks the output and deadline as part of the transaction. If those conditions pass, the final tokens go to to.
Before calling it, make sure the router is approved to spend at least amountIn of your input token. The router calls transferFrom to move those tokens from your wallet. Approval names the router as spender; it does not itself perform the swap.
Say you want to trade USDT for SUN on SunSwap V2 using a USDT→TRX→SUN path. You set USDT as the input, SUN as the output and TRX as the intermediate token. The router pulls USDT from your wallet and sends it to the first pair. That pair swaps USDT for TRX, and the router routes the TRX into the next pair to swap for SUN. The final SUN is sent to your chosen recipient if it meets amountOutMin before the deadline.
A successful V2-style swap commonly returns an array of amounts, with one amount for each token in the path. The first is the input amount; the last is the output amount. Intermediate entries show the amounts passed between hops. The actual output can differ from an earlier quote because pool prices can change before the transaction executes.
Why can the whole route revert?
A router route is atomic: every hop must succeed for the trade to complete. If one hop fails, the transaction reverts and its contract state changes roll back. The router does not keep the input or partial output as a completed trade, because it does not hold the route’s liquidity; the pools do.
That all-or-nothing behavior protects you from receiving only part of a multi-pool trade. It does not make a failed transaction free: the network may still charge for the work used to process it, including Energy on TRON.
Common revert causes include:
- The router’s allowance is missing or too small, so transferFrom cannot pull the input.
- The output is below amountOutMin, or the deadline has expired.
- A required pair does not exist for one of the adjacent tokens in the path.
- The transaction runs out of Energy on TRON before execution finishes.
Before sending, confirm that the token addresses form a valid path, the router has enough allowance, your minimum output reflects the quote you are willing to accept, and the deadline gives the transaction enough time to execute. A route that fails any required check reverts as a whole.
- Approve the router to spend the input token before swapping.
- Pass the input amount, minimum output, ordered token path, recipient and deadline.
- Each pool handles one hop; the router connects the hops and returns per-hop amounts.
- A failed hop or check reverts the entire route, though network costs may still apply.
What might you need to know next?
How does a Universal Router differ from a V2 router?
A V2 router is built around swaps through V2-style liquidity pools and paths of token addresses. A Universal Router is designed to handle a broader set of trade actions in one transaction. Check which actions and tokens the specific router supports before choosing its call parameters.
How do you quote amountOutMin before sending the swap?
Get a quote for your input amount and path from the DEX’s router or quoting contract. Set amountOutMin below that expected output by a margin you are willing to accept for price movement and slippage. A tighter minimum gives less room for the trade to execute at a worse price, but makes a revert more likely.
How do fee-on-transfer tokens change which router function to call?
A fee-on-transfer token may deliver less to a pool than the nominal transfer amount. Some V2 routers provide swap functions that account for this by checking the amount actually received. If the router lacks that support, a standard swap can fail or produce less output than expected; check the router’s available functions for the token you are integrating.