Skip to content

How to Swap on a DEX, Step by Step

Swapping on a decentralized exchange looks simple: connect a wallet, pick two tokens, click swap. What's happening underneath, and where new users actually lose money, is worth understanding before you try it.

Last updated July 2026

What actually happens when you swap

A decentralized exchange, or DEX, doesn't match your order against another trader's order the way a centralized exchange does. Most DEXs use liquidity pools: pairs of tokens locked into a smart contract by liquidity providers, priced against each other by a formula built into the contract. When you swap, you're trading directly against that pool, not against another person, and the pool's pricing formula shifts the exchange rate slightly with every trade based on how much of each token is left inside it.

This is why a DEX doesn't need an order book or a matching engine. It also means the price you see quoted before you swap isn't guaranteed to be the price you actually get, because the pool's balance, and the price it implies, can shift between the moment you see a quote and the moment your transaction actually confirms on-chain.

Slippage and price impact

Slippage is the difference between the price you expected and the price you actually received. It has two main causes. Price impact is the first: your own trade moves the pool's balance, and the larger your trade relative to the pool's total size, the more the price shifts against you as the trade executes. A small swap in a deep pool barely moves the price; a large swap in a shallow pool can move it substantially.

The second cause is the delay between submitting your transaction and it actually confirming. In that window, other trades can execute first and shift the pool's price before yours goes through. Every swap interface lets you set a slippage tolerance, the maximum price movement you'll accept before the transaction reverts rather than executing at a worse price. Setting it too tight can cause your swap to fail repeatedly in a fast-moving market; setting it too loose exposes you to a materially worse price, and in extreme cases, to the sandwich attacks described further below.

Token approvals: what you're actually signing

Before a DEX's smart contract can swap a token out of your wallet, you have to explicitly grant it permission with an approval transaction. This is a separate, distinct step from the swap itself, and it's specific to how tokens on smart-contract chains work: a contract can't move your tokens without your prior authorization.

Where this becomes risky is the scope of the approval. Many interfaces default to requesting an unlimited approval, meaning the contract can move any amount of that token from your wallet indefinitely, not just the amount for this one swap. That's convenient because you won't need to approve again on your next trade, but it also means if that contract is later exploited or turns out to be malicious, everything you've approved is exposed, not just what you intended to trade. Reviewing and revoking old, unused approvals periodically is one of the most overlooked habits in self-custody.

Step-by-step: your first swap safely

Start by connecting your wallet only to the DEX's official URL, typed directly or from a bookmark, never a link from a search ad or a message, a habit covered in more depth in common crypto scams. Confirm the token contract addresses you're swapping match the official ones for that project; scam tokens frequently copy a legitimate project's name and logo on a fake contract.

Start with a small test swap before committing a larger amount, especially on a token or pool you haven't used before. Check the quoted price impact the interface shows you; if it's unexpectedly large for a small trade, the pool likely has thin liquidity and isn't a good venue for that size. Set a reasonable slippage tolerance, review exactly what you're approving before signing, and only then confirm the swap.

MEV and sandwich attacks, briefly

A sandwich attack is when a bot spots your pending swap in the public mempool before it confirms, places its own trade immediately before yours to push the price against you, lets your trade execute at that worse price, then immediately sells back after, pocketing the difference. It's a specific application of the broader concept covered in what is MEV, and it's a direct financial cost to swaps with loose slippage tolerance, especially larger ones on pools with thin liquidity.

Tighter slippage tolerance limits how much a sandwich attack can extract from any single trade, since the attacker can only push the price as far as your tolerance allows before your transaction would simply fail. Some wallets and DEX aggregators also route transactions through private channels that aren't visible in the public mempool before confirmation, which removes the visibility a sandwich attack depends on entirely.

A pre-swap safety checklist

Before confirming any swap: verify you're on the official site, verify the token contract address rather than trusting the name and logo alone, check the price impact shown for your trade size, set a slippage tolerance that's tight enough to limit sandwich exposure but loose enough to avoid constant failed transactions, and read exactly what you're approving, including whether it's a limited or unlimited approval, before signing.

None of this is complicated once it's a habit, and the underlying wallet security covered in private keys and seed phrases still matters more than any single swap decision. But skipping these checks is exactly how most DEX-related losses happen, and they're avoidable with a few extra seconds of attention before every trade.

Keep learning DeFi

Free · No sign-up · Part of the LabelYX Learn series