How Decentralized Exchanges Work: Complete Tutorial

·

Ever wondered how you can swap tokens without a company like Coinbase in the middle? This guide explains exactly how decentralized exchanges work under the hood.

The Problem DEXs Solve

Traditional exchanges use order books—lists of buy and sell orders waiting to be matched. DEXs like Uniswap replaced order books with Automated Market Makers (AMMs).

How AMMs Work

Instead of matching buyers and sellers, AMMs use liquidity pools and a mathematical formula to determine prices:

x × y = k

Where:
x = Amount of Token A in the pool
y = Amount of Token B in the pool
k = A constant that never changes

Understanding Price Impact

Price Impact Curve
How trade size affects your price

The larger your trade relative to the pool, the worse your price. Always check price impact before trading—aim for under 1%.

DEX Trading Fees

DEXStandard Fee
Uniswap v30.05% / 0.30% / 1%
SushiSwap0.30%
Curve0.04%
PancakeSwap0.25%

Key Takeaways

  • DEXs use AMMs instead of order books
  • x × y = k formula determines prices mathematically
  • Price impact increases with trade size relative to pool
  • Total cost = swap fee + price impact + gas fee
  • More TVL = better prices for large trades