Module 1 · Lesson 5 of 45

How a DEX works behind the scenes

⏱ 6 min read ● Beginner Module 1 · Foundations: what a DEX is & why

Under the hood, a swap is just a sequence of well-defined steps. Walking through one demystifies almost everything else.

One swap, step by step

  1. Connect your wallet. The site reads your public address to show balances. It still cannot move anything without your signature.
  2. Choose tokens and amount. Pick what you have and what you want; the DEX quotes an expected result.
  3. Approve (first time only). Before a contract can move a given token, you grant it permission once — a separate, small on-chain step. We cover this in the upcoming lesson on token approvals.
  4. Review and sign. Your wallet shows the rate, the fees and a minimum you will receive. Signing is the final, binding action.
  5. The contract executes. Your tokens go into a liquidity pool and the other token comes out — atomically, all-or-nothing.
  6. It settles on-chain. Seconds to a minute later, the trade is confirmed and visible to anyone on a block explorer.

Where the price comes from

Most DEXes do not match you with another trader. Instead you trade against a pool of two tokens, and a formula sets the price from the ratio of what is inside. The larger your trade relative to the pool, the more the price moves — the reason slippage and price impact exist. We unpack the math in Module 3.

"Atomic" is your friend

A swap either completes fully or not at all; it cannot half-execute and strand your funds. If conditions change mid-flight — say the price moves past your limit — the whole transaction reverts. On Ethereum you may still pay gas for the attempt, which surprises many newcomers.

How to verify anything

Every transaction has a hash you can paste into a block explorer — Etherscan for Ethereum, Solscan for Solana — to confirm exactly what happened. When in doubt, check the chain; it is the source of truth.

Key terms
Liquidity poolThe two-token reserve you trade against; its ratio sets the price.
Atomic transactionAn all-or-nothing operation that either fully completes or fully reverts.
Block explorerA public website (Etherscan, Solscan) for inspecting any on-chain transaction.
Transaction hashThe unique ID of a transaction you can look up to verify it.
!Common mistakes
  • Panicking when a transaction is 'pending' and submitting it again — you can end up paying twice.
  • Not knowing where to verify a trade. The block explorer always has the real answer.
  • Assuming the quoted price is guaranteed. It is an estimate until the block confirms — which is why slippage settings exist.
Finished reading? Track your progress through the journey.