⬆️ ⬇️

How to write a decentralized multiblockchein exchange in a day





This article is a report on my participation in the second stage of the hackathon, organized by karma.red . You can read more about the hackathon on a special page .



For those who like to read the code, not the article - the project repository .

')

Video lovers are also not offended :) In this video, you can listen to a brief summary of the article, see how the exchange is implemented step by step and see its work live.





An article by another hackathon participant from Vladivostok (the three organizers from Vladik and one from Ulan-Ude, the organizers of the online stage paid for flying and living in Moscow).



The photos in the article - Vadim Frantsev, the pictures are mine, from a quick presentation of the project to protect the project :) So, with the formalities over, let's go.



After issuing assignments , I had a choice - either to take up a decentralized exchange, or for an arbitration court. In the task with the court, it would be necessary to create a system with a reputation, to program the simulation. It would be too simple and a bit like my project in the first stage .



The work of the decentralized exchange is based on atomic interblockchain exchanges (swaps), I have long wanted to understand them, but all hands did not reach. After giving myself an hour to research (if I couldn’t figure it out, I’d have to go to court) I went to read. After reading the documentation for the implementation of exchanges for several blockchains, I realized that everything was easy and took over the exchange.



What is this decentralized exchange:









For simplicity, exchanges can be exchanged only through the currency of the exchange. In this case, the exchange will be able to initiate atomic exchanges in the blockchain of the exchange.



Since besides ethereum, there are no other blockchains with smart contacts now, so I chose it for prototyping. Its use in the military stock exchange seems unlikely due to the price of gas and its limitations. In this regard, there is some hope for EOS.



Atomic exchanges



You can read detailed documentation here . Very brief retelling:





Putting it all together









My implementation



I took this implementation as the basis for the atomic swap contract: github.com/AltCoinExchange/ethatomicswap . The peculiarity of this implementation is that for a new atomic exchange there is no need to deploy a new contract. Everything happens in it, as in a certain registry of atomic exchanges.



In this contract, I added the ability to manually specify the initiator and the second participant of the exchange, in order to specify them when initiating the exchange from the exchange contract. The final version is here .



The following has been implemented in the exchange engine :





In order not to write the interface, I wrapped the contracts in the designers for the smartz.io platform and secured the contracts through these designers, quickly obtaining an interface for managing the contracts.



I didn’t have enough time to demonstrate the exchange of the broadcast to bitcoin, so I showed the exchange of the broadcast from the rinkeby test network to the broadcast of their test network kovan:







A couple of pictures and links



Links to control panels for contracts signed by me (you need to install the browser extension metamask to access the ethereum blockchain from the browser). If you wish, you can enclose your





Pictures for unwilling to put extensions:



Registry Control Panel




Control panel exchange


Source: https://habr.com/ru/post/359134/



All Articles