What are atomic swaps
Atomic swap is an operation to exchange one cryptocurrency for another, which can be implemented instantly without having to rely on a trusted third party (intermediary) in the person of the exchange or exchange platform. As a result, control over the transaction is carried out exclusively by the parties involved in it.
Atomic swaps can be carried out both on the chain, that is, directly between the blockchains of different cryptocurrencies, and off-chain – outside the blockchain. The first such exchange was made on September 19, 2017 between Decred and Litecoin cryptocurrencies.
What causes the need for atomic swaps
The process of exchanging cryptocurrencies on exchanges and other specialized platforms can still be time-consuming and is often associated with high commissions. In addition, not all exchanges support all coins or the necessary trading pairs, as a result of which a trader who wants to exchange one cryptocurrency for another, is faced with the forced need for additional conversions.
To solve these problems, including the aforementioned risks of trusting a third party, the technology of atomic swaps was developed. It was first described back in 2013, but only recently began to be put into practice.
How does it work from a technical point of view
When performing atomic swaps, a time-based hash contract (HTLC) is used. As the name implies, an HTLC is a temporary smart contract that includes the generation of a cryptographic hash function that can be verified by the exchange participants.
In other words, HTLC requires the payee to confirm receipt of funds by the generation of a cryptographic confirmation of payment before the deadline. Otherwise, the transaction is invalidated, and the funds are returned 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 assumes that Alice goes to the exchange, replenishes her account and places an order to sell her LTC coins. In the case of an atomic swap, Alice can directly exchange her LTCs for BTC, which Bob has the right amount of.
Alice, as the initiator of the transaction, creates the address of the contract, which can be compared with a bank deposit box. Alice’s LTC is stored at this address during the swap process. To open it, Bob’s signature is required, as well as a number generated by Alice. It is very important that Alice does not share this number with Bob at this stage, since then he will be able to open the cell and collect all the funds there before the swap is completed.
The next step, Alice comes up with a secret number and creates its hash. A hash acts like a lock, while a secret number is the key. Bob looks at the contract address from Alice, makes sure that everything is in order, and then creates his own cell with the same key. To do this, Alice sends Bob the previously created hash, but to open the cell, he needs Alice’s signature.
From this moment on, Alice has a key, as well as the ability to sign a cell for Bob and, therefore, redeem funds tied to the address. After that, Bob is given the secret number he needs, which until now he did not know. Bob can use this secret number to open Alice’s cell and collect the funds due to him.
As you can see, the HTLC structures the transaction in such a way that the parties depend on each other to ensure the successful completion of the exchange. Transactions are created in such a way that if, for some reason, the transaction is terminated, all funds are returned to their owners after a certain period of time set by each party.
Is Lightning Network protocol necessary for atomic swaps
Contrary to a widespread misconception, the Lightning Network technology is not a prerequisite for the successful implementation of atomic swaps, but it can make the exchange process easier, faster and more efficient.
Like atomic swaps, the Lightning Network uses time-locked hash contracts, the difference is that while atomic swaps connect blockchains, the Lightning Network connects payment channels. This method assumes that Alice and Bob open a payment channel with Carol and exchange through Carol without having to trust her.
One and the same fundamental mechanism means that integrating the Lightning Network into atomic swaps is quite simple, as a result of which different Lightning networks can be interconnected in different blockchains. Thanks to this, the swap participant that opens payment channels on both blockchains can act as a payment processing or, for example, a decentralized altcoin exchange.
What is the difference between on-chain and off-chain exchanges
On-chain atomic swaps occur directly on the blockchains of exchanged cryptocurrencies, which for successful exchange, in addition to supporting HTLC, must also use the same hashing algorithm.
Off-chain atomic swaps allow the exchange of coins outside the blockchain, as an extension of the Lightning Network.
What cryptocurrencies support atomic swap technology
The first successful exchanges using atomic swap technology were conducted between Litecoin and Decred, Vertcoin and Bitcoin. They may have attracted increased community attention, but this is not limited to these cryptocurrencies.
It should be noted that for the successful implementation of atomic swaps in their initial implementation, the user needs to download blockchains of both currencies. For the average user, this process from a practical and technical point of view is completely inconvenient.
However, a solution to this problem has already been found, and it is likely that it will soon become available to a wide range of users. So, the Komodo project is working on the creation of its own decentralized exchange BarterDEX. In particular, its developers successfully conducted an atomic swap using the Electrum server, which allows you to interact with cryptocurrency without having to download the entire blockchain.
Moreover, Komodo team claims that after it successfully linked the Bitcoin and Ethereum blockchains and implemented the support of ERC-20 tokens, their BarterDEX exchange now supports p2p exchanges between 95% of all existing coins and tokens.
Other well-known projects that are actively working on the practical implementation of the concept of atomic swaps are Blocknet, which aims to create an Internet of blockchains based on Xbridge technology, Altcoin.io, working to create a decentralized exchange based on Plasma technology and a wallet with built-in atomic swap functions , and Atomic Wallet.
In tracking how a particular cryptocurrency is close to supporting atomic swaps with another asset, for example, a resource such as swapready.net will help.