How does a centralised crypto exchange actually work ?

How does a transaction actually occur ?

Sukhad Anand
Coinmonks
Published in
7 min readAug 8, 2021

--

I have been plagued with this question for a lot of days now. Searching the internet, trying to find out how a centralised crypto exchange actually works. There are many articles dealing with the differences between centralised and decentralised cryptocurrency on a surface level. No one goes into depth to actually explain how exactly a transaction occurs, after we press the buy/sell button.

Some of the major questions which come to my mind are:

  1. How do the exchanges support different coins on different blockchains ? Do they maintain wallets for each person on each of the blockchain (Like a wallet for XRP, Ether, Bitcoin)?
  2. Between which two wallets does the trade occur ? Does it occur between two people, one trying to sell and other trying to buy / or the cryptocurrency maintains a large pool and adds and subtracts from just that pool ?
  3. Are our wallets hot wallets(connected to the internet) or cold wallets(not connected to the internet)?
  4. Do our trades happen between people only on the exchange or anyone on the blockchain ?
  5. How do they actually transfer one crypto to another as in how do they actually convert BTC — ETH etc ?
  6. How do the rates of all the currencies, are almost same across all exchanges?

I searched google/saw many youtube videos, but I did not understand how this all took place. So, in this article I discuss my thoughts and all the knowledge I got from my friend. I think, the way we think it works is quite close to how it actually works.

Before starting about how a cryptocurrency exchange works, let’s start with what is cryptocurrency ? I will try to explain it in as simple a way as possible.

So cryptocurrency is nothing but a decentralised currency. The currencies we use for our day to day transactions are centralised currencies. They are controlled and regulated by each country’s government. Cryptocurrency on the other hand is not regulated by anyone. Just the code regulates it. Yeah you read it right, code is law. So, a transaction between any two people, is not mediated by anyone, which on the other hand is done by the banks while making exchanges in some particular country’s currency. It is the bank which maintains the ledger of each person’s account transactions. You can go to your account and see all the transactions that you performed. In cryptocurrency, this ledger is distributed. It is not maintained by just one person, but everyone in the system called — blockchain. All the transactions are maintained in a distributed ledger. It is accessible to everyone. So anyone can see all the transactions, and no one can tamper it. This provides the highest level security to a decentralised transaction that no one can tamper it — not any government, not any bank, and no human error is possible. It is all code, and yes it can be hacked, but so can the bank servers which are much more vulnerable than a decentralised blockchain.

Now coming back to the topic for today, centralised exchanges. What role do they play in transactions over a blockchain? Well, they are the mediators of transactions on decentralised exchange. But how do they mediate the transactions on a blockchain, as no one can modify it. That’s where my curiosity began and made me come to all the above questions. Centralised exchanges make it convenient for people to exchange cryptocurrency and convert their actual currencies(USD/INR/EUR) to cryptocurrency. Without centralised exchanges, people would have to either use a decentralised exchange, which came much later after centralised exchanges and have its own issues associated with it. It is like a chicken and egg problem. You trade in just cryptocurrency on a decentralised platform, but how do you trade if you don’t have cryptocurrency.

Centralised exchanges act as a bank for cryptocurrencies. They handle the decentralised part of the transaction and they maintain an order book like the banks do. So, if a transaction occurs, you are not actually transacting on the blockchain, rather you are just transacting on a centralised exchange, who is just maintaining records for those transactions.

Below diagram shows the basic design of how a centralised exchange works.

For the sake of simplicity, let’s just discuss 3 functions:

  1. Deposit money into the exchange’s wallet.
  2. Buy cryptocurrency from the exchange.
  3. Sell cryptocurrency on the exchange.

Let’s tackle each of the questions step by step.

  1. Deposit Money: Using this API, the user can deposit fiat currency — USD/EUR/INR into the exchange’s wallet. This is simply done using a payment gateway which is used by the company. This money is then transferred to the company’s wallet. An entry of the user deposit is made in the db and this entry is used to reflect the amount of money the user has in the wallet.
  2. Buy crypto: Using this API, the user can buy any cryptocurrency which the exchange supports. When the user clicks on buy, no transaction actually occurs on the blockchain. Rather, the exchange uses a matching/trading engine to match a buyer with a seller and then updates the entries in db for seller and buyer accordingly. The exchange charges a fee for each transaction, which you can say fees for maintaining each transaction in their ledger.
  3. Sell crypto: Using this API, the user can sell any cryptocurrency which the exchange supports. Similarly like buying cryptocurrency, while selling too the same thing happens. The exchange just finds a matching buyer who is ready to buy at the same or greater price, as the person is selling.So, as we saw, there is nothing happening actually on a blockchain. It is just a company keeping the records and matching the orders. All you see in your wallet is just a database entry. Most of the centralised exchanges do not share the private keys of the user wallets. The reason for this is quite simple because they don’t have any user wallet. They have specific exchange wallets for each cryptocurrency, which comes in use when someone wants to transfer the their cryptocurrency to an actual wallet, whose private key they own themselves, rather than any exchange.

The cryptocurrency wallets which the exchange owns are used for these purposes and are also used to maintain the price of a cryptocurrency on the exchange as close as possible to all other exchanges. This is required because there are many different exchanges with different numbers of users on each exchange. It is possible that the rates vary because people on one exchange may be ready to sell/buy crypto on a lower/higher rate than any other exchange. This is done with the help of arbitrage.

Now coming back to each of the questions we discussed above:

  1. How do the exchanges support different coins on different blockchains ? Do they maintain wallets for each person on each of the blockchain (Like a wallet for XRP, Ether, Bitcoin)? — No, they do not, they just have a few wallets for each cryptocurrency which they use for P2P transfers/maintaining price.
  2. Between which two wallets does the trade occur ? Does it occur between two people, one trying to sell and other trying to buy / or the cryptocurrency maintains a large pool and adds and subtracts from just that pool ? — A transaction occurs between two people trying to buy and sell on the exchange, which results in just a database entry of the funds transferred.
  3. Are our wallets hot wallets(connected to the internet) or cold wallets(not connected to the internet)? — We don’t have any wallets, the exchange has some wallets as hot wallets and some as cold wallets. This depends on the exchange
  4. Do our trades happen between people only on the exchange or anyone on the blockchain ? — They happen only between 2 people on the exchange.
  5. How do they actually transfer one crypto to another as in how do they actually convert BTC — ETH etc ? — They just make a database entry, no conversion is actually being done
  6. How do the rates of all the currencies, are almost same across all exchanges? — This is done with the help of arbitrage.

I hope this answered a lot of your questions and helped you understand how a centralised exchange works. If not, this article must have raised some more questions and curiosity towards centralised/decentralised exchanges. I will be writing more articles about how things actually work from a software point of view, being a software engineer.

See you next time!!!!!!

Join Coinmonks Telegram Channel and learn about crypto trading and investing

Also, Read

--

--

Sukhad Anand
Coinmonks

Addicted to 007 movies and music of all genres and all generations. A bit of philosophy with a pinch of music and a handful of coding.