Home / Insights / What’s a DEX? How decentralized exchanges work

What’s a DEX? How decentralized exchanges work

Kirsty Moreland
Published February 16, 2024 1:54 am

Decentralized Exchange (DEX) definition

A DEX is a type of crypto exchange where users can trade cryptocurrency peer-to-peer, without any intermediary.

 

A decentralized exchange is a concept native to the blockchain ecosystem. It enables users to trade cryptocurrency with one another directly, or “peer-to-peer”. Unlike a traditional exchange, a DEX does not have any central entity or company coordinating it. Nor does it require you to deposit funds in a custodial exchange wallet; instead, you trade directly from your own crypto wallet.

All DEX transactions are controlled by smart contracts, which users agree to by “signing” with their crypto wallets. The smart contracts set the conditions for each trade, and execute the trade automatically when signed.

DEXs are often seen as a more transparent alternative to centralized exchanges. The details of every transaction are shown clearly by a smart contract before you sign. And furthermore, users  can retain complete control over their coins until a trade takes place – there is no need to deposit coins into a custodial wallet.

Decentralized exchanges are one of the key features of decentralized finance (DeFi). They give users access to a range of different tokens, all from within the blockchain ecosystem.

How does a DEX work?

A decentralized exchange creates a peer-to-peer marketplace where users can trade their cryptocurrency tokens. The exchange platform itself benefits from each transaction by charging a fee. 

So how does the exchange generate liquidity for transactions? Well, it all depends on what kind of decentralized exchange it is.

There are different types of DEXs, using different underlying mechanisms. The two principle varieties are order books and automated marker makers (AMM). Let’s take a look at each one.

Order book DEXs

In an order book system, the exchange receives “buy orders” from people wanting to buy a given token, and “sell orders” from users who want to sell their tokens. 

When a sell order comes in, the seller will set the price they want via something called a limit order. Meanwhile, buy orders are also coming in, with their own maximum price limit. Trades occur when buy and sell orders match in price and give both parties an optimal trade.

So in an order book DEX, users transact directly with one another. The exchange simply matches up corresponding buy and sell orders via an algorithm.

But the order book is not the only system for trading cryptocurrency.

Automated Market Makers (AMM)

Instead of matching individual traders, an automated market maker (AMM) uses liquidity pools to fulfill trades.

An AMM will be organized into “trading pairs”. For each possible trading combination, there will be two linked liquidity pools; one for each token.

So let’s say you wanted to exchange token X for token Y: an AMM would have a pool of X and a pool of Y set up to enable this trade. The tokens in these pools are provided by liquidity providers, who receive rewards for giving liquidity to the trading platform.

To execute your trade, you’d simply deposit your X tokens in the X liquidity pool for that paid. In return, you’d receive Y tokens from the corresponding Y pool. Liquidity pools are controlled by smart contracts, and the price of tokens is determined algorithmically. 

So in an AMM, you are not technically trading directly with another user. Instead, you trade with a liquidity pool, funded by a liquiduty provider who will be rewarded later on. 

Decentralized exchange costs

Like any exchange, DEXs are a service, and they make money from what they provide. In other words, you’ll pay a fee for transacting.

Exchange fees

In an order book system, you pay a fee directly to the DEX protocol for executing your trade. Meanwhile, in an AMM, you also pay a fee for transacting, but as well as paying the exchange, that fee also provides the reward for the liquidity providers enabling the liquidity pools.

Gas fees (network fees)

Beyond paying a premium to the DEX, you’ll also require to pay the network fees, or gas fees, of the blockchain you’re using. These fees become the validator rewards for the nodes keeping the network secure.

Advantages of decentralized exchanges

DEXs offer crypto users a way to trade their tokens without leaving the blockchain environment. There is no middleman or central entity, only a protocol, and other users providing liquidity. This offers a completely transparent, trustless process, as well as the convenience of peer-to-peer transactions. 

DEX users also value the control they have over their crypto; trades happen directly from your crypto wallet, and you will never cede custody to the exchange.

Disadvantages and risks

DEXs also come with unique disadvantages and risks.

Limited liquidity

Liquidity is a big issue, for example, since both types of exchange rely on their users to provide trading liquidity. In an order book system, buy orders can only be serviced if there are sufficient matching sell orders. And while AMMs counter this problem by operating designated liquidity pools, these pools are also dependant on liquidity providers.

Slippage

Exchanges offer rates that are constantly changing, and prices can change dramatically over a short period of time. This can be a problem when your network is congested.

Slippage is the change in price between when you agree to a transaction, and when it is executed by the blockchain. With major blockchains famously struggling to manage network traffic, slippage can make a significant difference to your exchange terms.

Smart contract risks

Every interaction with a DEX is governed by a smart contract, which is great if you know exactly how to read them. But for many people, smart contracts are still very technical – when you hit “confirm” you might not really know what you’re agreeing to. This is a great opportunity for hackers, who have in the past deployed malicious smart contracts on DEX interfaces to clean out users’ wallets.

In short, with no middleman or central company to take responsibility, being scammed on a DEX means saying goodbye to your crypto. 

No fiat exchanges

And finally, with DEXs operating entirely on blockchain with no external entity, they are a crypto only zone. Unlike a centralized crypto exchange run by a real-world company, there is no way of “buying” crypto with fiat, or off-ramping from crypto.