Step 1: Alice first “deposits” assets into a smart contract. This process can work differently for different DEXs and in some cases has varying terminology, but it’s fine to think of this step as a deposit in the traditional sense. However, unlike a CEX, the DEX has no control over the deposit. At this point, only the user is allowed to touch the assets via either a withdrawal or a trade submitted to the contract.

Step 2: Alice signs an order to buy a crypto-asset. For example, she would like to buy some Basic Attention Tokens (BAT). She sends the order to the DEX’s off-chain orderbook servers to store and share with other users. The signed order effectively amounts to a message that reads “Alice authorizes a trade of 1 ETH (owned by her) for 1000 BAT (from someone else)”. She signs the message with her private key to prove that it came from her.

Step 3: Bob comes along and takes Alice’s order from the DEX’s off-chain orderbook. Some DEXs require Bob to find the order himself by browsing the orderbook (similar to how one would browse listings on eBay). Other DEXs provide automated matching.

Step 4: Bob deposits enough BAT to the smart contract to cover the opposite side of Alice’s order. He does so using the same process Alice used in Step 1. After completing his deposit, Bob signs a blockchain transaction that includes Alice’s signed order and his authorization to be a counter-party to that order. He submits this transaction to the trade function of the smart contract. The funds get swapped in the smart contract. Alice is credited BAT and debited ETH, and vice versa for Bob.

Step 5: Alice is now free to withdraw her BAT by sending a transaction to the blockchain. The DEX interface can help her construct and submit this withdrawal transaction, but she has the option of doing it with zero assistance from the DEX. That means she can withdraw regardless of the state of the DEX, a hugely powerful advantage. Ideally, the DEX or her wallet app would have offline functionality to construct blockchain transactions and queue them for delivery.

That’s a complete trade!

DEXs are evolving, and we are seeing the emergence of some hybrid exchanges which are not as black and white as the examples here, but this accurately approximates many DEXs today.

For a more thorough explanation of how decentralized exchanges work, check out the following content from around the web:

Understanding Decentralized Exchanges by Dominiek Ter Heide

Decentralized Cryptocurrency Exchanges by Phil Glazer

Benefits of Using a Decentralized Exchange

1. Control of Funds

One of the most compelling aspects of a decentralized exchange is that it gives customers complete control over their assets. Customers on centralized exchanges must deposit their funds onto the exchange in order to conduct transactions. This means that funds on centralized exchanges are held by the central party’s wallet. The customer’s access to their funds is dependent on that central party. If a centralized exchange goes offline, the customer cannot access their funds.

In addition to availability concerns, centralized exchanges are a large target for hackers because all funds are stored by one entity. The reward-to-work ratio of hacking a centralized exchange is much more attractive than hacking each individual user in a decentralized exchange.

On decentralized exchanges, customers have the ability to transact directly between wallets through the exchange’s orderbook (or even directly). The users have full control of their funds at every step.

2. Security

Thanks to the advent of blockchain technology, decentralized exchanges essentially operate on a distributed ledger where security is greatly enhanced. Users interact on a trustless and a non-custodial platform. As long as users are not careless with their private keys, they have a greater degree of control over their accounts and transactions on a decentralized exchange.

Even if a decentralized exchange frontend were to be compromised, the user’s wallet software provides another line of defense. In this scenario, the compromised frontend might request a transaction that sends funds to a fraudulent address instead of the real DEX smart contract. The user would have to approve the requested transaction with their wallet software. If the wallet clearly presents the approval request with a well-designed UI, it would be possible for a user to spot an improper transaction destination and decline the approval. It is even possible for wallet software to detect sudden, suspicious changes in destination addresses in a similar fashion to how browser vendors collect and push malware and phishing URLs to browsers to warn their users when they click known malicious links.

Thanks!

Thanks for reading. Have questions? Something we should explain further? Ask by tweeting EverbloomHQ on Twitter or chatting in our Telegram group. The Everbloom DEX is live! See our announcement post.

About the Authors

Andrew Rollins (Twitter): CEO and co-founder of Everbloom | Former developer at Microsoft and VC at Sigma Prime | Previously Chief Software Architect and co-founder of Localytics | Blog at Andrew Rollins on Medium.

Andrew Hall (LinkedIn): Business Development Associate at Everbloom | Studying Finance and C.S. at Wake Forest University | Investor / Trader in Traditional and Crypto Markets.

Eric Nemeth (LinkedIn): Business Development Associate at Everbloom | Studied Economics at Boston College | Interested in tokenizing real assets | International traveler | Futbol loving Chelsea fan.

Footnotes

[1] Bitcoin: A Peer-to-Peer Electronic Cash System; https://bitcoin.org/bitcoin.pdf

[2] What is a wallet? Learn more: https://en.wikipedia.org/wiki/Cryptocurrency_wallet and https://cryptocurrencyfacts.com/what-is-a-cryptocurrency-wallet/

[3] The term “off-chain” means “outside of any blockchain.” The term is used to specify that an action happens outside of the purview of any blockchain (the action has no effect on the blockchain and the blockchain is not aware of the action). The term is also used to specify that a piece of data does not reside on the blockchain.