What Is a Decentralized Exchange (DEX) and How Does It Work?
- Primary Signal: What Is a Decentralized Exchange (DEX) and How Does It Work?
- Overview: A DEX is a crypto marketplace that runs on smart contracts instead of a company. One complete trade worked through the AMM math, the full dollar cost, and a DEX vs CEX cost compari...
- Verification: Analyzed and compiled by 1UpTrade Quant editorial monitoring desk.
A decentralized exchange, or DEX, is a crypto marketplace that runs on smart contracts instead of a company. You trade directly from your own wallet, and the smart contract swaps your tokens. There is no account, no deposit, and no one holding your coins.
A trade works in four steps. You connect your wallet to the DEX. You choose the two tokens and the amount. You approve the token spend, then sign the swap. The smart contract executes the trade and the tokens land in your wallet in the same transaction. If any step fails, the whole trade reverts.
Most DEXs use an automated market maker, or AMM. A pool holds two tokens, and the price comes from their ratio. The pool follows one rule: the two balances multiplied together stay constant. That rule is written as x times y equals k.
Here is one trade worked through the math. A pool holds 100 ETH and 200,000 USDC, so the price is $2,000 per ETH and k is 20,000,000. You buy 1 ETH. The pool then holds 99 ETH, so it must hold 20,000,000 divided by 99, which is $202,020.20 of USDC. You pay $2,020.20 for $2,000 of ETH. The extra $20.20 is slippage, which is 1.01%.
The fee sits on top. At a 0.3% swap fee, you pay 0.3% of $2,020.20, which is $6.06. Your total cost is $2,020.20 plus $6.06, which is $2,026.26 for 1 ETH. The fee goes to the people who supplied the pool, not to a company.
Bigger trades cost more, because each token you buy makes the next one pricier. Buying 10 ETH from the same pool leaves 90 ETH, so the pool must hold 20,000,000 divided by 90, which is $222,222.22. You pay $22,222.22, or $2,222.22 per ETH on average. That is 11.11% slippage. Pool size sets the price you actually get.
Compare the same $1,000 trade on both kinds of exchange. On a centralised exchange with a 0.1% taker fee, the fee is $1.00. On a DEX with a 0.3% fee, the fee is $3.00, plus the network gas fee and any slippage. The DEX costs more per trade, but the exchange never holds your coins. The FTX collapse is the reason many traders accept that trade-off.
There are three kinds of DEX. AMMs like Uniswap price trades from pools. Order-book DEXs like dYdX and Hyperliquid match buyers and sellers like a normal exchange. Aggregators like 1inch split your trade across pools to find the best price. For most beginners, an AMM or an aggregator is the starting point.
Set your slippage tolerance before you swap. For liquid pairs, 0.5% to 1% is normal. For small pools, 1% to 3% is common. A tolerance set too low means the trade fails. A tolerance set too high invites front-running, where a bot sees your trade and buys ahead of you.
The risks are real. Smart contracts can have bugs. Fake tokens can look like real ones. A failed transaction still costs gas. And there is no fiat off-ramp — you cannot withdraw dollars from a DEX. Check the token contract address, not just the name, before every swap. What is a gas fee in crypto and how is it calculated?
Q: Is a DEX safer than a centralised exchange? A: Safer from exchange collapse, because the exchange never holds your coins. Riskier in other ways: smart-contract bugs, fake tokens, and no support desk if you send funds to the wrong address.
Q: Do I need an account to use a DEX? A: No. You connect a wallet such as MetaMask. There is no email, no password, and no identity check. Your wallet address is your account.
Q: What is impermanent loss? A: It is the loss liquidity providers take when the two tokens in a pool change price relative to each other. The pool sells the rising token and buys the falling one, so providers can end up with less than if they had simply held both tokens.
Q: Why did my swap fail but still cost gas? A: The transaction was recorded on the blockchain even though the swap reverted, usually because the price moved past your slippage tolerance. The network still charges gas for the failed attempt.