Academy ⟶ Blockchain

What are Atomic Swaps & Why do we need them?

Atomic swaps can be implemented both on-chain - between two blockchains, and off-chain - outside the blockchain. The concept of cross-chain trading is innovative. Daniel Larimer introduced the P2PTradeX protocol considered to be the first prototype of the atomic swap in 2012. The communities of Bitcoin, Litecoin, Komodo, and Decred have played a significant role in the development and growth of this technology.

7 min

Table of Contents

Introduction

An atomic swap is a tool that allows users to trade two cryptocurrencies based on different blockchains. This process takes place instantly and without the need to trust a third party (an exchange platform). The supervision of the transaction is carried out by the parties involved. Such a method (also known as atomic cross-chain trading) is based on smart contracts and helps users to exchange coins directly from their storage wallet.

Atomic swaps can be implemented both on-chain - between two blockchains, and off-chain - outside the blockchain. The concept of cross-chain trading is innovative. Daniel Larimer introduced the P2PTradeX protocol considered to be the first prototype of the atomic swap in 2012. The communities of Bitcoin, Litecoin, Komodo, and Decred have played a significant role in the development and growth of this technology. The first atomic swap between Decred and Litecoin took place on 19/09/2017.

Why do we need atomic swaps?

The process of trading cryptocurrencies on exchanges and other specialized platforms takes a lot of time, requires registration, identity verification, has high fees, and more. In addition, not all exchanges support the necessary coins or trading pairs, as a result of which the trader is forced to make additional transactions and pay further fees.

Atomic swap technology has been developed to resolve these problems, as well as the risks of trusting third parties.

How does it work?

Atomic swap protocols are designed to avoid the manipulation of the parties concerned. Suppose that Bob decides to exchange his Litecoin (LTC) for Alice’s Bitcoin (BTC). Bob makes an LTC deposit to the contract address, which serves as a safe deposit. When this safe deposit is generated, Bob will generate a key to access it, and then transfer the cryptographic hash of that key to Alice. But, she can’t receive LTC because she just got the hash of the key, not the key itself. Next, Alice uses the hash provided by Bob to create another contract address that stores her BTC. To receive BTC, Bob must use the same key, giving his LTC to Alice (thanks to a special hashlock feature). As soon as Bob requests for BTC, Alice, in turn, will also request for LTC, and the currency exchange will be done.

If Bob or Alice fails to comply with the terms, the smart contract is canceled and the funds are immediately returned to their owners.

Atomic swaps can take place in two different ways: on-chain and off-chain.  In this case, On-chain swap occurs on the Bitcoin and Litecoin networks. Off-chain swap occurs in the second layer. This form of swap is based on two-way payment channels similar to those used in the Lightning Network.

Trusted trading systems are based on smart contracts that use multi-signatures and Hash Timelock Contracts (HTLC).

HTLC is a temporary smart contract that generates a cryptographic hash function that can be verified by the exchange participants. the use of HTLC removes the need for trust. HTLC demands that the receipt of funds be confirmed by producing a cryptographic proof of payment before the time limit expires, otherwise, the transaction will be invalid.

Why Atomic Swap technology is important?

Atomic swaps have great potential to improve the cryptocurrency world. Cross-chain trading can solve many problems of centralized exchanges, that include:

Storing huge volumes of assets makes them prime targets for hacker attacks. There are also exist human factors of inefficient management. Since centralized exchanges are operated by people, they can make mistakes. The management team of the exchange can make a wrong decision in relation to trading operations, and users’ funds may be stolen, frozen, or lost. Also, exchange platforms have set high transaction and withdrawal fees. Among other problems, if the trading volume is too high, many of them cannot cope with it, which leads to a slowdown or even to a suspension of the system. Finally, there are too many legal concerns related to cryptocurrencies, with the regulation, control, and interpretation of digital assets by governments.

Lightning Network and atomic swaps

Lightning Network technology makes the exchange process easier, faster, and more effective. The Lightning Network as well as atomic swaps use time-locked hashing contracts. The key difference is that atomic swaps links blockchains, while the Lightning Network links payment channels. This method involves Bob and Alice opens a payment channel with John and making an exchange “through” John without the need to trust.

It is easy to integrate the Lightning Network into atomic swaps. A swap participant who opens payment channels can serve as a payment processor or decentralized exchange.

Atomic swaps Benefits

Decentralization is the most significant advantage of atomic swaps, excluding the need for centralized platforms or intermediaries. Cross-chain exchanges can take place without confidence between two, three (or more) parties. The level of security is high since users do not need to transfer their funds to a centralized exchange or to a third party. All transactions are made directly between user wallets. Such a p2p transaction type has lower operating costs, and thus, transaction fees are very small or non-existent. Atomic swaps allow users to exchange instantly and altcoins can be traded directly without the use of Bitcoin or Ethereum as an intermediary coin.

Atomic swaps Disadvantages

Atomic swaps also have drawbacks. In order to exchange, the two cryptocurrencies must be based on the blockchain which uses the same hashing algorithm, compliant with HTLC and other features. Atomic swaps are not anonymous, this type of exchange can be tracked using the blockchain explorer, which makes it easy to link addresses. Many developers are working with digital signatures for atomic swaps.

Stay in Touch

Academy

Learn about blockchain, cryptocurrencies, DeFi, wallets and get useful guides.

Start Learning

Newsletter

We send a brief email usually once every two weeks with news, giveaways, and updates. We'll never share your address with any third party.

Our Blog

Read our blog to stay up to date on Guarda news, new features, and press releases.

Read Blog

Latest articles in Blockchain

What is Binance Smart Chain?

What is Binance Smart Chain?

Binance Smart Chain (BSC) is a blockchain that runs in parallel with the Binance Chain. Unlike Binance Chain, BSC has smart contract functionality and compatibility with the Ethereum Virtual Machine (EVM). Binance Smart Chain is based on a system with up to 21 Proof-of-Stake-Authority (PoSA) consensus validators, that requires minimal block validation time and offers much lower fees.

9 min
Who are WallStreetBets, Elon Musk, and what is the crypto meme?

Who are WallStreetBets, Elon Musk, and what is the crypto meme?

Low-income retail investors, hedge funds, institutions, corporations, commissions, and panicked brokers; you might expect to find these terms in the script for a new Hollywood movie such as The Big Short or The Wolf of Wall Street.

6 min

The referral program is on! Don't miss out.