What are atomic swaps?
Atomic swaps consist of a technology that allows the rapid exchange of two digital transactions running on different distinct blockchain networks. Such a process, also known as atomic cross-chain trading, is based on so-called smart contracts and allows users to trade their digital currencies directly from their personal digital wallets. So atomic swaps are essentially peer-to-peer trades that operate across different blockchain networks.
Although it is an innovative technology, the idea of cross-chain trading has been discussed for many years. Tier Nolan was probably the first to describe a complete atomic swap protocol in 2013. However Daniel Larimer introduced an untrustworthy swap protocol in 2012 that some people consider to be the prototype of atomic swap.
In the following years many developers began experimenting with atomic swap protocols. Evidence suggests that the Bitcoin, Litecoin, Komodo, and Decred communities all played an important role in this process.
The first peer-to-peer atomic swap was started in 2014. But this technology became widely known by the general public only in 2017 due to the successful swaps between LTC/BTC and DCR/LTC.
How do atomic swaps work?
Atomic swap protocols are designed in a way to prevent any of the parties involved from cheating. To understand how it works, let's imagine that Alice wants to trade Litecoin (LTC) with Bob, who owns Bitcoin (BTC).
First, Alice deposits her Litecoin (LTC) into a contract address that acts as a vault. When this safe is created Alice also creates a key to access it. You then share the encrypted hash of this key with Bob. Note that Bob cannot access LTC yet because he only has the hash of the key and not the key itself.
Bob then uses the hash provided by Alice to create another secure contract address into which he deposits his Bitcoin (BTC). To claim the bitcoins, Alice must use the same key and in doing so reveal it to Bob (thanks to a special function called a hashlock). This means that once Alice claims Bob's Bitcoin, Bob is also able to claim Alice's Litecoin and the swap is complete.
The term ‘atomic’ relates to the fact that these transactions occur either completely or not at all. If either party gives up or fails to do what they should, the contract is canceled and the money is automatically returned to the owners.
Atomic swaps can occur in two different ways: on-chain and off-chain. In-network swaps occur on either of the currency networks (in this case the Bitcoin blockchain or the Litecoin blockchain). Off-network swaps, on the other hand, occur on a secondary layer. This type of atomic swap typically relies on two-way payment channels similar to the channels used in the Lightning Network.
Technically, most trustless trading systems rely on smart contracts that use multi-signatures and Hash Timelock Contracts (HTLC).
Hash Timelock Contracts (HTLC)
While HTLC is an important part of Bitcoin's Lightning Network, it is also one of the key components that makes atomic swaps possible. As the name suggests, it is based on two main functions: the Hashlock and the Timelock. Therefore, using Hash Timelock Contracts eliminates the need for trust because they create a specific set of rules that prevent atomic swaps from being partially executed (until all parts of the swap are completed).
A hashlock is what prevents money from being spent unless a piece of data is revealed (such as Alice's key in the previous example) and a timelock is a function that ensures that a contract can only be executed within a pre-determined time frame. Thus, the use of HTLCs eliminates the need for trust because they create a specific set of rules that prevent atomic swaps from being executed partially (until all corners of the swap are completed).
Advantages
The biggest advantage of atomic swaps is its decentralized nature. By removing the need for a central exchange or any other type of intermediation. Cross-chain swaps can be executed by two (or more) parties without the need for trust between each other. There is also an increased level of security because users do not need to give their funds to a central or third-party trading platform. Instead, trades can occur directly between users' personal wallets.
Also this type of peer-to-peer trading has much lower operating costs as trading fees are either very low or non-existent. Finally, atomic swaps allow trades to occur very quickly with higher degrees of interoperability. In other words, digital currencies can be exchanged directly without the need to use Bitcoin or Ethereum as an intermediary currency.
Restrictions
There are some conditions that must be met to perform an atomic swap. These conditions likely represent obstacles to the widespread adoption of this technology. For example, to perform an atomic swap, the cryptocurrencies involved in the swap must be running on a blockchain network that shares the same hashing algorithm (such as SHA-256 for Bitcoin). They also need to be compatible with HTLC and other software functions.
Otherwise, atomic swaps raise concerns about users' privacy. This is because online transactions and swaps can be quickly tracked on the blockchain explorer. This makes it easy to link addresses to their owners. The short-term solution to this problem is to use privacy-focused cryptocurrencies as a way to reduce owner disclosure. However, many developers are experimenting with using digital signatures in atomic swaps as a more reliable solution.
Why is it important?
Atomic swaps have great potential to improve the cryptocurrency space and still need to be tested on a larger scale. On-chain trading could eventually solve many of the problems that are part of centralized trading platforms. Although these platforms have maintained digital currency systems until today, there are many concerns about them. Some of these problems include:
More vulnerable: Keeping many valuable resources in one place makes them more vulnerable to hacking or theft. Centralized trading platforms are prime targets for digital theft.
Mismanagement of Funds and Human Error: Centralized trading platforms are run by people. If people in important roles make mistakes or if leaders make poor choices regarding the platform itself, users' funds can be put at risk.
Higher operational costs: Centralized trading platforms have higher withdrawal and trading fees
Inefficiency in order volume: When market activity becomes intense, centralized trading platforms often fail to handle the increased order volume, causing system slowdowns or Internet outages.
Law: In most countries the legal regulation of cryptocurrencies is far from perfect. There are still many concerns surrounding government approval and management.
Concluding thoughts
Although atomic swaps are still fairly new and certainly have limitations, this technology is driving major changes in terms of blockchain interoperability and cross-chain trading capabilities. As such, this technology has great potential to influence the growth of the cryptocurrency industry and open new ways in terms of decentralization and direct cash transfers. It is expected that atomic swaps will be used more and more in the near future, especially in decentralized trading platforms.

