You may have noticed the suffix “EX” appears a lot while studying or working with cryptocurrencies?
“EX” is short for EXchange and there are literally tens of them, perhaps over one hundred.
Why so many?
Perhaps the best way to illustrate why there are so many crypto exchanges is through a practical example.
Johnny, a cryptocurrency enthusiast, bought his first Bitcoins early in 2010. It was really cheap back then and he had tons of BTC’s just sitting there.
Then came Litecoin and Dogecoin and in just a few years Johnny was holding a bag of 10 or so different cryptocurrencies that were rapidly gaining dollar value.
Suddenly, he realized that he had become his own bank. And, as part of the process, he had all the necessary open source software to run his bank for free!
Johnny then realizes that every cryptocurrency wallet has a programmable interface embedded in it.
The Bitcoin wallet can be programmed and so can the Litecoin, Dogecoin and just about every other wallet.
And most of them work in a very similar way!
They all share a common API, or “application programming interface”.
Johnny then programs his Bitcoin wallet to send and receive Bitcoins whenever he sends it a secret command using his cell phone. Cool! He could now impress friends and family by sending them Bitcoins from anywhere!
But what useful (and profitable?) applications could be created using the API?
If your guess is that 9 out of 10 programmers immediately thought of creating their own exchange, then you’ve answered the question at the top of this article!
What if you could interface your Bitcoin wallet, running in your bedroom, to Paypal or some other fiat money payment gateway?
Boom. You’ve built a Bitcoin exchange.
That’s what BitcoinMarket.com did way back in 2010. Bitcointalk user dwdollar announced BitcoinMarket.com in January of that year and sparked a gold rush for wallet API developers.
What about exchanging Bitcoin for other cryptocurrencies? Remember Johnny was holding a bag of several cryptos? Well….
Johnny buys a box of Club Mate and sits down to program his own crypto exchange. It creates one address per user using the wallet API for every specific cryptocurrency listed in the exchange.
All he has to do is keep all these wallets running 24×7 and keep the database safe. This database tracks who owns which address from which cryptocurrency.
The rest happens on the blockchain.
When given a cryptocurrency address, users send funds to this address and the JohnnyEX system immediately updates the database with your new balance. When you wish to withdraw, the exchange sends a command to this wallet to send the funds back to you and the database is updated accordingly.
When the user wishes to exchange one currency for another, JohnnyEX matches the top bid against the lowest ask. If they match, the trade happens and the database is updated accordingly.
Just like Johnny created his own EXchange in his bedroom, so did tens of other talented programmers.
Is it really that simple?
Creating a cryptocurrency exchange is not rocket science.
The main challenge in running an EX is to keep it secure from hackers. That’s where most exchanges have historically failed.
Hackers can target the main wallet that receives and sends funds for a given cryptocurrency. Wallets may contain security flaws that specialized hackers will exploit. The database itself could be exploited by somehow changing the balances to add or subtract nonexistent amounts.
Take MtGox as an example.
One day MtGox’s creator, Mark Karpeles, is asking basic beginner questions on PHP programming language forums.
A short time later he’s running MtGox.
This real life example shows how simple it is to interface any programming language to the wallet API’s. The API’s are easy to use, well documented (thanks Bitcoin Core team!) and anyone can program them using any programming language.
Unfortunately, MtGox is also an example of poor programming and administrative practices. Whether MtGox was hacked or an enormous fraud, or a combination of both, the fact remains that thousands of people lost hundreds of million of U$ due to the MtGox collapse.
DEX vs CEX
MtGox illustrates a recurring problem with all centralized exchanges (CEX). Most exchanges we currently use are centralized. Which means that someone runs a central database (like JohnnyEX) that keeps track of balances, deposits, withdrawals and trades from one cryptocurrency to another.
These exchanges are especially vulnerable to hackers, because they must keep large sums of cryptocurrency online in order to execute timely deposits and withdrawals.
Enter DEX – decentralized exchanges.
A DEX is a smart contract that accepts remote commands on the blockchain.
A deposit would be a command accompanied by some amount of cryptocurrency. A withdrawal would be a command that would check the requesting addresse’s balance and, if all went well, would send this amount to the requester.
Since the exchange runs on the blockchain, there’s no centralized database. Everyone holds a copy of the deposit and withdrawal amounts on their own copy of the blockchain.
DEX Crosschain Traffic
There’s an obvious problem with the above smart contract: it only runs on one blockchain.
An Ethereum smart contract would be able to manage ETH along with any Ethereum-based token (ERC20 or newer). This is because all Ethereum tokens live on the ETH blockchain and the smart contract has access to data on its native blockchain.
To be able to create a universal DEX, you’d need crosschain transactions.
At the time of this writing there are many efforts to create reliable and secure crosschain interfaces. Until these interfaces are up and running, it won’t be possible to mix several blockchains into one smart contract.
We hope this article answered your question! Yes, there are many cryptocurrency exchanges but you should choose wisely.
Early programmers enjoyed creating applications for their own wallets and most these apps involved some form of exchange with the outside world.
The “EX” mania exploded in the early years of Bitcoin and derived cryptocurrencies and lots of these early experiments are still around.
Programming your very own bank can be real fun. That’s the origin of so many exchanges – to have fun developing software for the cryptocurrency revolution!
Crowded Market Photo Credit: Ville Miettinen from Helsinki, Finland by CC via Wikipedia
Work & Learn