Atomic Swaps, allows the safe(atomic) peer to peer exchange of different cryptocurrencies without a centralized party being involved in the transfer process. Still a centralized party is required for order matching and to facilitate the trade execution. In order to do this both chains must support smart contracts.
Nov. 2017: Bitcoin and Litecoin executed the first off-chain atomic swap using the Bitcoin Lightning Network
Sep. 2017: Decred and Litecoin on-chain atomic swap
How does it work
John owns BTC and Mary owns LTC. Both of them want to do a peer to peer atomic swap. They will find an online platform similar with the ones for torrents that will facilitate the swap by showing matching offers. If both of them agree on a price, they will initiate the swap.
First John with the help of the online platform will execute the first transaction on the BTC chain deploying a smart contract. A random password will be generated by the platform and then a one way hash will be applied to it. The public contract will only accept interaction from users that have the original password and will hardcode the owner’s main wallet address in it for refund purposes. The second transaction will be a transfer from it’s own wallet to the newly swap wallet.
The smart contract will allow funds retrieval in two ways: after 48 hours will allow John to submit a refund transaction in case something went wrong. John can be identified based on his wallet address. But for the first 24 hours only Mary can execute a translation that will move the funds from the swap wallet to her own personal BTC wallet, only if she can provide the original password.
Mary is next. She will receive the password hash via email or other communication channel. The platform could also automatically manage the receiving of the hash and create a new LTC swap contract on the LTC chain. The contract will be locked by the same hash. Only the original password known by John at this point can be used to initiate a transfer from this wallet. It will allow Mary to execute a refund transaction at any point by registering the funds source address. It will also allow Joth to transfer from this swap wallet to his own LTC wallet if he can provide the password.
John initiates the first LTC transfer from the swap to his own wallet. But by doing this his passwords get publicly visible on the ledger. Mary can now use this password and move the money from the swap BTC wallet to her personal BTC wallet.
Things to consider
There is no actual transfer between the two chains and there are three wallets involved on each chain.
Mary could lose her BTC if she doesn’t do the transfer in the first 24 hours because John can trigger the refund after.
The 48 hours limit for John is to protect Mary from edge cases. John could wait until the last minute to execute his transfer. Because the 24 hours are up he could also execute the refund.
Lightning Network would make Atomic Swaps instantaneous, private, and free.
Atomic Swap in the wild