Module 1: Introduction to Crypto Markets
Where Crypto Trades: Decentralised Exchanges
Chapter 8 of 15 · about 7 minutes
8.1 An exchange with no company
After learning about exchange collapses in Chapter 7, Node had a sharp question. "If the problem is trusting a company with my money, can I trade without one?"
"You can," said Hash. "That's what a decentralised exchange is. No company holds your funds. You trade directly from your own wallet, against a smart contract."
A decentralised exchange (DEX) is a set of smart contracts on a blockchain that lets people swap one token for another. There's no sign-up, no account, and usually no KYC. You connect a wallet, choose what to swap, approve the transaction, and the swap happens on-chain. Your assets stay in your own wallet until the moment of the trade.
8.2 The problem with order books on a blockchain
Centralised exchanges match buyers and sellers using an order book: a list of everyone's buy and sell offers at different prices. Doing this on a blockchain is difficult. Every new order, change, and cancellation would be a transaction costing gas, and blockchains are much slower than an exchange's servers.
Some DEXs do use order books, especially on fast blockchains and specialised networks. But the design that made DEXs popular took a completely different approach.
8.3 Automated market makers
Instead of matching buyers with sellers, most DEXs use an automated market maker (AMM). Here's the idea.
Picture a jar of marbles and a jar of coins on a shop counter, connected by a rule. Anyone can add marbles and take coins out, or add coins and take marbles out. The rule decides how many you get, and it's designed so that the scarcer one item becomes, the more expensive it gets.
On a DEX, these jars are called a liquidity pool. A pool might contain ETH and a dollar stablecoin like USDC. When Mint wants ETH, Mint adds USDC to the pool and takes ETH out. Nobody on the other side needs to be online. The smart contract is always ready to trade.
The most common rule is simple: the quantity of one token multiplied by the quantity of the other must stay constant. It's often written as x × y = k.
Where does the money in the pool come from? From liquidity providers, people who deposit both tokens into the pool. In return, they earn a share of the trading fees, often around 0.3% of each trade, though fees vary. Being a liquidity provider has its own risks, which we'll cover in the DeFi module.
8.4 A worked example: why pool size matters
Let's see the rule in action with a small pool, ignoring fees to keep the maths clean.
The pool holds 10 ETH and 30,000 USDC. The price implied by the pool is 30,000 ÷ 10 = $3,000 per ETH. The constant k is 10 × 30,000 = 300,000.
Mint wants to buy 1 ETH. After the trade, the pool will have 9 ETH. To keep k at 300,000, the USDC side must become 300,000 ÷ 9 = 33,333.33. So Mint has to put in 33,333.33 minus 30,000 = $3,333.33 for 1 ETH.
That's about 11% more than the starting price. This difference between the expected price and the price you actually get is called slippage, and it happens because Mint's trade was large relative to the pool.
Now the same trade in a much bigger pool: 1,000 ETH and 3,000,000 USDC. The starting price is still $3,000.
| Small pool | Large pool | |
|---|---|---|
| Starting ETH | 10 | 1,000 |
| Starting USDC | 30,000 | 3,000,000 |
| Starting price | $3,000 | $3,000 |
| Cost to buy 1 ETH | $3,333.33 | $3,003.00 |
| Slippage | ~11.1% | ~0.1% |
| Pool price after the trade | ~$3,704 | ~$3,006 |
The lesson: liquidity matters. The deeper the pool, the less your trade moves the price. Before swapping, always check the expected price impact your DEX shows you.
Notice the last row too. After Mint's trade, the small pool now prices ETH at about $3,704, far above the wider market. Arbitrageurs will quickly sell ETH into the pool until its price lines up with other markets again. That's how DEX prices stay connected to the rest of the world.
Chapter 8 · Why pool size matters
In a small pool of 10 ETH and 30,000 USDC, buying 1 ETH costs about $3,333, an 11% price impact. In a large pool of 1,000 ETH and 3,000,000 USDC, the same 1 ETH costs about $3,003, only a 0.1% price impact.
8.5 What a swap costs
On a DEX, Mint pays several costs that are worth separating.
Pool fee. A percentage of the trade paid to liquidity providers.
Price impact or slippage. The cost of moving the pool's price, as shown above.
Network gas fee. The cost of the blockchain transaction itself, which depends on the network and how busy it is. On some networks this is a few cents. On a busy Ethereum mainnet it can be much more.
Interface fee. Some apps that sit on top of the DEX add a small fee of their own.
DEXs let you set a slippage tolerance, the maximum price change you'll accept. If the price moves more than that before your transaction is confirmed, the swap fails instead of executing at a bad price. Setting it too high can expose you to bots that deliberately move the price against you, a topic we'll cover in Module 3.
8.6 Centralised and decentralised compared
| Centralised exchange | Decentralised exchange | |
|---|---|---|
| Who holds your funds | The exchange | You, in your own wallet |
| Account and KYC | Usually required | Usually not required |
| Local currency deposits | Yes | Generally no, crypto only |
| How trades are matched | Order book run by the company | Mostly liquidity pools and smart contracts |
| Available tokens | Selected and listed by the company | Anyone can create a pool for any token |
| Customer support | Yes | Generally no |
| Main risks | Exchange failure, hacks, frozen withdrawals | Smart contract bugs, fake tokens, user mistakes |
8.7 Freedom cuts both ways
Because anyone can create a pool for any token, DEXs list everything, including tokens that don't exist anywhere else yet. That's how many new projects first become tradable. It's also how many scams operate.
"So I could buy a fake token by accident?" Mint asked.
"Easily," said Hash. "Anyone can create a token called 'USDC' and put it in a pool. Remember Chapter 5: the contract address is the identity, not the name."
Other risks to know about:
Token approvals. Before a DEX can move your tokens, you approve its smart contract to spend them. Approving a malicious contract, or granting unlimited approvals carelessly, can let an attacker drain those tokens later. Module 2 explains how to review and revoke approvals.
Smart contract risk. Even well-known DEX contracts can have bugs, and newer or copycat DEXs carry much more risk.
Rug pulls. A token's creators can add liquidity to a pool, wait for buyers to arrive, then withdraw all the liquidity at once, leaving buyers holding a token they can't sell.
Phishing sites. Fake websites imitate popular DEXs to trick people into signing harmful transactions. Bookmark the real site rather than clicking links.
Node summed it up. "So a DEX removes the company risk but hands all the responsibility to me."
"That's the trade," said Hash. "In crypto, it usually is."
8.8 Try it yourself
Open a well-known DEX interface without connecting a wallet. Most let you get a quote without signing in. Enter a swap of a small amount, say $100 of ETH for USDC, and note the price impact. Then increase the amount to $1,000,000 and see how the price impact changes. You've just seen liquidity depth in action.
If you want to try a real swap, use a testnet version of a DEX with free test tokens, so mistakes cost nothing. Module 2 will walk you through setting up a wallet first.
Key takeaways from this chapter
- A decentralised exchange lets you trade directly from your own wallet using smart contracts, with no company holding your funds.
- Most DEXs use automated market makers, where trades happen against liquidity pools priced by a formula such as x × y = k.
- Liquidity providers supply the pools and earn trading fees.
- Large trades in small pools cause significant slippage. Pool depth is critical.
- DEX costs include pool fees, price impact, gas, and sometimes interface fees.
- DEXs offer freedom and self-custody, but bring risks like fake tokens, malicious approvals, rug pulls, smart contract bugs, and phishing.