Trading between cryptocurrencies can be difficult and depending on how obscure the coin may be, the process could involve using obscure, low volume cryptocurrency exchanges before you get the crypto you wanted. Multiple transactions incur multiple fees and throw in the risk of market volatility by the time you finish and most people conclude it’s not worth the trouble.
So why is it so difficult to trade from one cryptocurrency directly to another? Cryptocurrencies exist in different blockchains and coins can’t move between blockchains because they are incompatible. Since that fundamental hurdle of blockchain software is yet to be solved, there are different proposed solutions for going around the problem, and atomic swaps are one of the possible solutions.
What are Atomic Swaps?
An atomic swap is a means of exchanging digital assets across different blockchains without involving third parties. The difference between atomic swaps and decentralized exchanges (DEX) is they represent a novel cryptographic protocol and eliminate the risks associated with performing the same trade on an exchange. Atomic swaps are executed in real-time and are an advanced version of decentralized exchanges that is safer, more efficient and trustless.
If, for instance, you want to trade your Bitcoin (BTC) for Ether (ETH) via a traditional cryptocurrency exchange you will need two separate transactions. You will have to sell BTC to the exchange before you can buy ETH from them. The exchange acts as a third party in this case and is in charge of your fund; there is always the risk of the exchange acting dishonestly or getting hacked in the worst-case scenario.
With an atomic swap, you don’t need a third-party as the swap is done on a peer-to-peer (P2P) basis. You agree on the exchange rate with the other party and once you confirm if you complete the trade.
How Atomic Swaps work
Atomic swaps work like Lightning Network transaction using a Hashed Timelock Contract (HTLC) that protects the interests of both parties in the transaction. This special smart contract uses a multi-signature transaction system that holds both parties’ funds until the swap is successful.
The hashlock uses a cryptographic algorithm that only allows accessing their digital asset once both sign off their respective transactions. You may compare the timelock with to an insurance policy that ensures both traders will have their funds back if the trade fails within a given timeframe.
Step by step
Let’s use Bob and Alice where Bob has BTC he wants to change for ETH while Alice has ETH she wants to swap for BTC.
Step 0
Bob posts a trade order on a DEX. This is listed as Step 0 because, technically, it’s not part of the atomic swap process.
Step 1
Alice sees Bob’s offer, accepts it and commits to paying the swap fee; the fee ensures traders don’t spam the network. Bob doesn’t pay any transaction fees. The atomic swap commences once Alice pays the fee.
Step 2
Bob deposits the funds in a secure address where neither he, Alice nor any third party has access until the trade is completed or times out. The refundable deposit is 112% of the amount to remove any incentives to cheat.
Step 3
Alice sends her ETH to a second secure address where no one can touch it until the end of the swap. If the trade fails at this point or gets canceled Bob’s BTC deposit and Alice’s ETH deposits are returned.
Step 4
Bob sends his BTC payment to Alice and finishes his part of the deal; only Alice can claim Bob’s BTC payment.
Step 5
Alice accepts Bob’s BTC and once she accepts it, Bob gets the green light to claim Alice’s ETH payment.
Step 6
Bob accepts Alice’s ETH and both parties get what they wanted and the swap is successful.
Step 7
Once both parties have received their funds, Bob reclaims his deposit, and the swap is completed.
Can all cryptocurrencies perform atomic swaps?
At the moment not all cryptocurrencies can do atomic swaps. Most virtual currencies have hashing algorithms and time locked contracts but don’t have the special programming tools to enable them to interact with other blockchains.
Atomic swaps are a giant step towards blockchain interoperability allowing users to exchange their cryptocurrencies between different blockchains. Komodo operates atomic swap technology that builds bridges between most of the existing coins ensuring that crypto users are not stranded on small blockchain islands.