A swap is the exchange of one cryptocurrency token for another through a DEX or aggregator — the most fundamental DeFi operation, executed atomically in a single blockchain transaction.
WHY IT MATTERS
Swaps are DeFi's core primitive. Instead of selling Token A for fiat and buying Token B (the centralized exchange flow), a DEX swap atomically exchanges them in one transaction. If any step fails, the entire swap reverts.
The swap flow: user approves token spending, submits swap transaction with parameters (input token, output token, amount, slippage tolerance), the DEX router finds the best path through available pools, and the swap executes.
DEX aggregators (1inch, Paraswap) optimize swaps by routing through multiple DEXs and pools simultaneously, finding the best price across the ecosystem.
FREQUENTLY ASKED QUESTIONS
How does a swap work technically?
The DEX router calls the pool's swap function with your tokens. The pool calculates the output amount based on its formula, transfers output tokens to you, and takes your input tokens. All atomic.
What's token approval?
Before a DEX can spend your tokens, you must approve its contract. This is an ERC-20 approve() call. Be cautious with unlimited approvals — they persist and could be exploited if the contract is compromised.
Should I use an aggregator or a direct DEX?
Aggregators almost always give better prices for significant amounts. They split trades across multiple pools and DEXs. For tiny trades, the gas overhead may not be worth it.