Summary

That brings us to the end of this chapter. This chapter should help you design decentralized trading exchanges, or exchanges on a distributed blockchain network in general. It should also help you to port concepts of trading, such as orderbooks and matching engines, to blockchain very easily. The example case that we looked at uses only a single orderbook pair, gold versus US dollars, but it can be very easily expanded to support multiple orderbook pairs and assets, and can be scaled into a full-sized exchange with additional components and security checks in place. You can run this on a private blockchain for an enterprise, or deploy it on a public blockchain. Bear in mind that public blockchains will require gas for each transaction, and you might want to club transactions together. Also, your orderbook will be visible to everyone on the public blockchain.

We started the chapter by looking at decentralized exchanges and some basic trading concepts. We deployed our trading assets, gold and USD, as ERC20 tokens. We charted out an orderbook smart contract in order to manage buy and sell orders and execute trades. Since anyone can access the contract and view the orderbook, it is a transparent orderbook. Lastly, we created an exchange app to allow the user to access and view the orderbook , submit buy/sell trades, and view their token balance. The exchange app also matches submitted buy and sell orders against existing orders in the orderbook, and adds new orders to the orderbook. Lastly, we ran our app to see how it functions.

The main takeaway from this chapter is understanding how to build decentralized systems, such as exchanges, using blockchain. Such systems remove the need to trust a third party for executing trades.

In the next chapter, we'll be building a currency swap exchange that builds on this decentralized trading concept, and allows trading of currency assets on the Stellar blockchain network.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.42.168