Skip to the lesson
Back to the library
Lesson 608Digital assets4 min readLast reviewed 28 November 2026

More digital assets lessonsAll lessons

SWAPS BY SMART CONTRACT

Decentralised exchanges: trading crypto without a middleman.

How decentralised exchanges let users swap tokens directly from their wallets, how automated market makers and liquidity pools set prices, the costs of slippage and fees, and the risks for traders and liquidity providers.

See the example
Decentralised exchanges: trading crypto without a middleman. — photo illustration
608 / SWAPS BY SMART CONTRACTPhoto illustration
01

The idea

A decentralised exchange, or DEX, lets people trade crypto tokens directly from their own wallets using smart contracts on a blockchain. There is no company holding customer funds or matching orders in the traditional way. Uniswap, Curve and similar protocols are well-known examples.

At a glance
How a DEX swap works — infographic
02

Automated market makers

Most DEXs use automated market makers rather than order books. Users called liquidity providers deposit pairs of tokens into a pool. The smart contract sets prices using a formula, such as keeping the product of the two token amounts constant. Traders swap against the pool, and prices move as balances change.

03

Centralised versus decentralised

FeatureCentralised exchangeDecentralised exchange
CustodyExchange holds your assetsYou keep your assets in your wallet
AccountSign-up, identity checksConnect a wallet
PricingOrder bookLiquidity pool formula
Token listingsChosen by exchangeAnyone can create a pool
SupportCustomer serviceNone; transactions are final
04

Slippage

When you trade a large amount relative to a pool’s size, the price moves against you during the trade. This is slippage. Wallets let you set a maximum slippage, and trades fail if the price moves too far, though failed transactions still cost gas.

05

Fees

Traders pay a swap fee, often between 0.05% and 1%, which goes to liquidity providers and sometimes the protocol, plus network gas fees. On busy networks, gas can exceed the swap fee.

06

Liquidity providers and impermanent loss

Liquidity providers earn fees but face impermanent loss: if the prices of the two tokens diverge, the pool rebalances so they end up with more of the weaker token. If price changes are large, fees may not make up for this.

07

Scam tokens

Because anyone can create a token and a pool, DEXs list many scams: copycat tokens with familiar names, tokens that cannot be sold, and rug pulls where creators withdraw liquidity. Checking the official contract address from the project’s own channels is essential.

08

Front-running and MEV

Some bots watch pending transactions and trade ahead of them, profiting at traders’ expense, a practice known as maximal extractable value, or MEV. Tight slippage settings and private transaction services can reduce exposure.

09

Smart contract risk

DEX contracts can contain bugs. Large, audited and long-running protocols are generally safer than new forks offering high rewards, though none are risk-free.

10

Regulation

Regulators are still deciding how to treat DEXs and their front-end websites. Users remain responsible for complying with tax and other rules where they live.

11

When DEXs are used

People use DEXs to trade tokens not listed on centralised exchanges, to keep custody of their assets, or to access decentralised finance services. Beginners often find centralised, regulated platforms simpler and safer.

12

Aggregators

DEX aggregators search many pools to find the best price, splitting trades across them to reduce slippage. They add convenience but rely on additional contracts.

13

Concentrated liquidity

Newer DEX designs let liquidity providers place funds within chosen price ranges, earning more fees when prices stay in range but taking more impermanent loss if prices move outside. This suits active managers more than passive providers.

14

Checking a pool

Before trading a less-known token, look at the pool’s size, how long it has existed, whether liquidity is locked and how many holders the token has. Small, new pools with concentrated holders are higher risk.

15

Keeping records

Every DEX trade is a taxable event in many countries. Because there are no account statements, keeping your own records or using portfolio tools that read your wallet history makes tax reporting easier.

16

Gas versus trade size

On the Ethereum main network, small trades can be dominated by gas costs. Many DEXs now operate on layer-2 networks and other chains where fees are far lower, which makes small swaps practical.

17

A realistic scenario

Hassan wants to swap 5,000 dollars of stablecoins for a token on a DEX. The pool is small, and the quote shows 4% slippage. He splits the trade into smaller parts using an aggregator, cutting slippage to under 1%, and checks the token’s contract address against the project’s official site first.

18

Questions to ask yourself

Ask yourself
  • Is this the official token contract?
  • How much slippage will I face?
  • What are the swap and gas fees?
  • Is the protocol audited and established?
  • Would a regulated exchange be simpler?
19

The short version

Decentralised exchanges let users swap tokens from their own wallets using liquidity pools and smart contracts. They avoid custodial risk but bring slippage, scam tokens, front-running and code risk.

Worked example

Illustration: pool holds 100 ETH and 300,000 USDC (price 3,000). Buying 10 ETH under the constant-product formula costs about 33,333 USDC, an average of about 3,333 per ETH, or 11% above the starting price, before fees. Hypothetical pool.

The idea to take with you

DEXs let you trade from your own wallet using smart contracts. They remove the exchange as custodian but add risks of scams, slippage and code failures.

Sources & assumptions

Primary educational references

Ethereum.org · Decentralised exchanges ↗

Investor.gov · Crypto assets ↗

Reviewed November 28, 2026. Examples are hypothetical illustrations. Educational content, not personalised investment, legal or tax advice.