Lykke Exchange under maintenance following security incident. Inactive until further notice. Read updates here.
Back to blog

What is an atomic swap?

Date
16/11/2020
Written by
Lykke
Share
Leave your opinion (0 reviews)

Atomic swaps are made up of a mechanism that allows a fluid exchange of two different cryptocurrencies, running on distinct blockchain networks. This process (also known as atomic cross-chain trading) is based upon smart contracts, and it allows users to trade their currencies directly from their personal crypto wallets. So atomic swaps are, essentially, peer to peer trades across different blockchain networks.

Despite being this sounding very much like an innovative process - the idea of cross-chain trading has been under discussion for many years. Tier Nolan was likely the first to describe a complete atomic swap protocol, back in 2013. However, a trustless exchange protocol called P2PTradeX was presented by Daniel Larimer in 2012, with some people considering it to be the prototype of an atomic swap.

In the following years, many developers then started to experiment with atomic swap protocols. Evidence suggests that Bitcoin, Litecoin, Komodo, and Decred communities all played an important role in the process of bringing it to the forefront.

The first peer to peer atomic swaps started to take place in 2014. But it wasn't until 2017 that the process became widely known by the general public - mainly due to the successful swaps between LTC/BTC and DCR/LTC.

But how does an atomic swap work?

An atomic swap protocol is designed in a way that prevents any of the involved parties from cheating the system. To understand how they work, let’s imagine that Mike wants to trade his Litecoin's (LTC) for Angela’s Bitcoins (BTC).

First, Angela deposits her LTC into a contract address that acts like a safe. When this safe is created, Angela also generates a key to access it. She then shares a cryptographic hash of this key with Mike. Note that Mike can’t access the LTC yet because he only has the hash of the key and not the key itself.

Next, Mike uses the hash provided by Angela to create another safe contract address, in which he deposits his BTC. To claim the BTC, Angela is required to use that same key and, by doing so, she reveals it to Mike (due to a special function called hashlock). This means that as soon as Angela claims the BTC, Mike is able to claim the LTC and the swap is complete.

The term ‘atomic’ is called this due to the transactions either happening entirely or not at all. If any of the parties stop the process, the contract is canceled, and the funds are automatically returned to their owners.

Atomic swaps can happen in two distinct ways: on-chain and off-chain. On-chain atomic swaps happen on either of the currency’s networks (in this case, either the Bitcoin or Litecoin blockchain). Off-chain atomic swaps, on the other hand, take place on a secondary layer. This kind of atomic swaps is usually based on bidirectional payment channels, similar to the ones used in the Lightning Network.

Strictly speaking, most of these trustless trading systems are based on smart contracts that use multi-signatures and Hash Timelock Contracts (HTLC).

Summary

Although atomic swaps are still fairly new in terms of technology with limitations, this technology is driving significant changes in regards to blockchain interoperability and cross-chain trading capabilities. As such, the technique has great potential to influence the growth of the wider cryptocurrency industry, opening up new avenues in terms of decentralization and peer to peer monetary transfers. The chances are that atomic swaps will be used more and more in the near future, especially within decentralized exchanges.

Share this