What Is Atomic Swap?
What is an atomic swap?
An atomic swap is an operation of trading one cryptocurrency for another instantly without a third party, such as an exchange. As a result, the deal is controlled only by the parties involved.
Atomic swaps can be conducted either on-chain (i.e. directly between blockchains of two different cryptocurrencies) or off-chain (i.e. outside of blockchain). The first atomic swap took place on September 19th, 2017, between Decred and Litecoin blockchains.
Why are atomic swaps necessary?
The process of exchanging cryptocurrencies on specialized platforms can be time-consuming and involves relatively high fees. Not all platforms support every coin and the required pairs, so a trader willing to exchange one asset for another has to make extra conversions.
By 2013 the idea of atomic swaps came about as a solution to both the problem of exchange accessibility and the problem of trusting a third party.
How does it work in theory?
Atomic swaps are conducted using Hashed Timelock Contracts (HTLC). As the name implies, HTLC is a time-dependant smart-contract that involves generating a cryptographic hash that can be verified by the parties of the deal.
HTLC requires the recipient of the transaction to cryptographically confirm that the funds are received. Otherwise, the transaction is deemed invalid and the funds go back to the sender.
How does it work in practice?
Alice has 100 LTC, which she wants to exchange for an equivalent amount of BTC. The traditional mechanism implies that Alice should go to an exchange, replenish her balance and make an order for selling her LTC. In case of an atomic swap, Alice can exchange her LTC directly into BTC, that are owned by Bob.
As an initiator of the transaction, Alice creates a contract address, which is similar to a bank deposit cell. This address holds Alice’s LTC during the swap process. Unlocking the address requires Bob’s signature and a number generated by Alice. It is important that Alice doesn’t share this number with Bob yet, because it would allow him to withdraw all the funds before the swap is completed.
At the next step, Alice comes up with a secret number and generates a hash from it. This hash acts as a lock, while the secret number is the key. Alice sends Bob the hash. Bob views Alice’s contract address, checks if everything is right, and then creates his own address with the same key. He is still unable to unlock the address without Alice’s signature.
Now Alice has the key and can sign Bob’s cell, effectively withdrawing the funds. Subsequently, Bob receives the secret number and uses it to unlock Alice’s cell and collect his funds.
HTLC structures the transaction in such a way that a successful completion depends on both parties. If a deal is somehow interrupted or cancelled, after a set amount of time all funds will return to their owners.
Is Lightning Network necessary for atomic swaps?
Lightning Network is not a required condition for atomic swaps, but it can simplify the procedure.
Similar to atomic swaps, Lightning Network technology uses Hashed Timelock Contracts. Yet, while atomic swaps connect blockchains, Lightning Network connects payment channels. It means that Alice and Bob open a payment channel with Caroll and exchange funds via this intermediary without needing to trust Caroll.
Since Lightning Network and atomic swaps use the same basic mechanism, these two technologies can be integrated easily. As a result, different Lightning Networks can be connected to each other in different blockchains. A swap participant that opens payment channels on both blockchains can act as a payment processor or a decentralized altcoin exchange.
What is the difference between on-chain and off-chain swaps?
On-chain atomic swaps occur directly in the blockchains of the cryptocurrencies being swapped. These two blockchains have to support HTLC and use the same hashing algorithm.
Off-chain atomic swaps are an extension of Lightning Network that allows users to swap coins outside of a blockchain.
Which cryptocurrencies support atomic swaps?
First successful atomic swaps took place between Litecoin and Decred blockchains, and Vertcoin and Bitcoin. These instances were probably the main reason behind the community interest in the technology. However, atomic swaps are not limited to the aforementioned cryptocurrencies.
In order to conduct atomic swaps in their initial implementation, one would need to download the blockchains of both cryptocurrencies in question. For an average user, the process is complicated and impractical.
However, better solutions are already being implemented.
Komodo is developing a decentralized exchange BarterDEX. They had successfully conducted an atomic swap via Electrum server, that allows for interaction with cryptocurrency without downloading its entire blockchain. Moreover, Komodo claims that connecting Ethereum and Bitcoin blockchains and implementing ERC-20 token allowed BarterDex to support p2p-swaps between 95% of the existing coins and tokens.
Among other notable projects working on atomic swap implementation are: Blocknet, which develops “internet of blockchains” based on Xbridge technology; Altcoin.io, working on a Plasma-based decentralized exchange and a wallet with atomic swap features Atomic Wallet.
There are specialized websites allowing users to monitor how far away certain cryptocurrencies are from implementing atomic swaps. One of those is swapready.net.
Subscribe to our Newsletter<
- Samson Mow: Bitcoin Is a Way to Prevent an Orwellian Future
- Lightning Network and Mass Adoption: What’s Missing?
- Blockstream’s Christian Decker On Latest Lightning Network Developments And What Bitcoin Could Be Like In Future
- Blockstream’s Lightning Network Upgrade Featuring Plugin Functionality Released
- Bitcoin Users Can Now Enjoy ForkLog’s Lightning Network Node
- New Bundle of Lightning Network Business Products Released by Bitfury
- Bitcoin Transaction Volume in 2018 Exceeds $410 Billion
- Sky Is No Limit – Blockstream Bitcoin Satellite Service Boosted With Lightning Network Payments