Tuesday, January 30, 2018

How to Add Swaps to your Cryptocurrency Exchange?

In the world of Cryptocurrency "Swaps" is a concept or feature in the exchange that helps in Swapping one cryptocurrency to another. Some also call this as a Bitcoin escrow script. There is however a difference between the normal conversion of one Alt-coin to another within your account against the concept of Swapping.

Note: BitExchange is a ready-made Bitcoin Exchange Script with Swaps feature builtin

Lets understand it with an example: Jenny owns 8748 Ripple's and would like to convert it into Bitcoins. The normal way to do it is via. transferring it to an established exchange like Binance, Cex.io and inside your account selling the Ripple's and buying back Bitcoins instead. But here there is a trusted 3rd party involved and there is a commission for the transaction. The other way to do it is via. Swaps. Say on the other hand Thomas has 1 Bitcoin and wants to convert it to Ripple's. Seeing Jenny's request on a forum, he can contact Jenny for the transfer. This transfer directly happens between Jenny and Thomas without a middle tier. Just powered by technology.

To add Swaps or cross-chain trading in any exchange, it can be done using either of the two ways:
- Using a regular Escrow
- On-Chain  Atomic Swap.
- Off-Chain Atomic Swap.

Even before we speaking about how the above 2 ways can be implemented, lets look at a very important factor that needs to be considered when implementing Swaps in your online Bitcoin Exchange. Taking the same above example: when the swap happens between Jenny and Thomas, there needs to some mechanism to ensure that the transaction happens successfully and both parties get what they have expected. Or there is always a chance that one party may receive the Alt-coin and not initiate the transfer from his side, which is bad. So to achieve this type of concrete transaction, we need to implement a strong digital contract -or- a smart contract in place that oversees the entire transaction.

* Using On-Chain Atomic Swaps:

This is the most common method used. Also large amounts can be swapped using On-Chain Atomic Swaps. This is not dependent on a Lightning Network or Segregated Witness ( Segwit ). This type of Swaps can be easily programed using SCRIPT language. Here in, 2 parties A & B can swap the digital assets they have without a trusted 3rd party exchange in-between. A digital smart contract is created to execute the swap in just 1 transfer ( instead of the traditional 2 transfers happening ). The contract is constructed to roll back if all the pre-defined rules of the contract does not happen. The contract is also time bound and rolls back if the transaction does not happen within the time period. The programming logic the contract is bound in sends out the Private keys to both the parties. When one side of the transaction is executed, the public key is revealed on the other parties blockchain and the next transaction is also executed.

* Using Off-Chain Atomic Swaps:

Off Chain or Cross chain Atomic Swaps is the latest technology or technique to achieve a safe and reliable swap between 2 parties. This concept uses HTLCs ( Hash time-locked Contracts ) to execute the swap. HTLC is a form of a smart contract, wherein its programmed to check if all the conditions mentioned in the contract are executed successfully before the overall transaction is complete -or- everything gets rolled back to how it was. This entire process is achieved by the usage of a cryptographic hash from both the involved parties. Both Jenny and Thomas should initiate the transaction from blockchain's of their respective cryptocurrency ie. Ripple Blockchain & Bitcoin Blockchain. If any of the party does not confirm the unique cryptographic hash within the dealine of the contract....it gets rolled back.

While we use the Hash Time-locked Contract ( HTLC ) to execute the terms of the contract, we need to process the financial transaction using a Lightning Network. The initial trials of Atomic swaps required the downloading of the Blockchains of each Alt-coin, which made the entire process cumbersome. The recent advancement in servers and service providers allows any exchange to implement Atomic swaps by using existing servers like Electrum. Other exciting projcts like Lykke, Blocknet facilitate the usage of Atomic swaps with a use of a network of Blockchains that be easily called by the exchanges directly and quickly.One other thing to note is that though many altcoins and Bitcoin support swaps, some coins like Monero do not have atomic swapping capabilities yet.

* Escrow:

The less complicated way of achieving Swaps in your Bitcoin exchange script is via. using the good old Online Escrow mechanism. The process may not be as quick and seamless as the Atomic swap, but it serves the purpose.  Once both parties initiate a transfer, the coins get to a common wallet of the Exchange. Based on the pre-set terms and rules of the transaction, the admin of the exchange checks to see if the conditions are met. If all seems ok, the coins are swapped. Here the admin may also put a commission for the work done by him. 

What is a Bitcoin escrow script?

The word escrow inself means ther is a trusted 3rd party during a transaction, who validates the entire transaction and than approves it. Incase there is a discrepancy in the transaction the Escrow reverses the entire transaction. In a good bitcoin escrow script, the escrow is 100% taken care automatically by advanced technology. To achieve this level of automation, your bitcoin escrow script should employ atomic swaps. A bitcoin escrow script that runs using atomic swaps are very secure and lightning fast. There is a smart contract that governs the entire transaction and plays the role of the escrow.

No comments:

Post a Comment