What Is An Atomic Swap?

Atomic Swap Explained

Share this article

Bitcoin was meant to usher in a world of decentralised finance, where you would not need to trust a third party to transact. Still, most users acquire or trade Bitcoin via a third-party centralised exchange. Centralised exchanges (CEX) offer a familiar trading experience that you would find when trading paper contracts like stocks, fiat or options.

Centralised exchanges also provide asset liquidity, manage trading pairs and order books, ensure fair market prices, and connect buyers and sellers on a platform.

To achieve this smooth trading experience offered by CEX’s, there are trade-offs in the form of giving up custody of your funds to the platform and jumping through several KYC hoops to set up an account. When you’re using a centralised exchange, you’re effectively trading on their internal database, which is meant to be backed by customers’ funds.

Despite calls for proof of reserves, leaving your money with centralised exchanges has been a dubious prospect with several high-profile failures in the past, along with bank runs that have left certain users destitute.

What is an atomic swap?

Atomic swaps, known as atomic cross-chain trading, have been around since July 2012, with Sergio Demian Lerner’s initial attempt at creating a trustless exchange protocol called P2PTradeX. Later the idea was further refined and formalised by Tier Nolan in May 2013.

Atomic swaps enable DeFi and solve the inefficiencies associated with CEXs by enabling the peer-to-peer exchange of cryptocurrencies between two parties without the need for a trusted third party.

Atomic swaps can be used to swap Bitcoin for altcoins running on separate chains, or they can be used to swap Bitcoin for Bitcoin in other protocol layers like the Liquid Network, Lightning Network or Statechains. The second option allows liquidity to flow into different layers faster because you need not action functions like a Lightning channel open or a Liquid Peg in, making it easier to move between systems.

How do atomic swaps work?

Bitcoin atomic swaps are possible thanks to two types of Bitcoin Smart contracts, the Hash Lock (Used to also create Lightning channels) and the Time Lock.

  • Hashlock. A hashlock is a cryptographically hidden key generated by the person that initiated a transaction. This key ensures that swaps are only finalized once both parties approve the transaction.
  • Timelock. Timelocks are created as a Check-Lock-Time-Verify command (CLTV) or Check Sequence Verify (CSV). With CLTV, funds within a transaction are locked or released based on date and time. If neither party approves the swap before a set time, the timelock acts as a safety mechanism and voids the transaction.

Here is a step-by-step overview of how atomic swaps work:

  1. The two parties agree to the terms of the exchange, including the funds that will be exchanged and the amount of each cryptocurrency.
  2. The sender creates an HTLC and sends it to the receiver. The HTLC specifies the hash of the cryptocurrency they are sending and the signature of the cryptocurrency they are receiving.
  3. The receiver signs the HTLC and sends it back to the sender.
  4. The sender checks the signature to make sure it is valid with the secret key recognised by the Bitcoin network.
  5. If the signature is valid, the sender releases the funds to the receiver.
  6. The receiver checks the hash to make sure it matches the cryptocurrency they received.
  7. If the hash matches, the receiver uses the secret key releases the funds to the sender.

How an atomic swap would work

Alice and Bob want to exchange 1 Bitcoin (BTC) for 350 Litecoin (LTC), but they do not wish to relinquish ownership of their coins or KYC with an exchange. 

Instead, they create an ad or offer on a decentralised exchange looking for a trading partner. Bob and Alice find each other’s trade terms attractive and initiate a trade. 

Bob first creates a secret number, a “value.” He then also generates a hash from this value, and he shares this hash with Alice without the secret value. 

Now Bob creates a Bitcoin transaction, “locking up” 1 BTC. This bitcoin can be claimed in a follow-up transaction in two ways. 

  1. It can be claimed by Alice, with her signature, in combination with the secret value. The Bitcoin network will recognise the secret value if it matches the hash, which is included in this transaction, passing through a successful trade. 
  2. Alternatively, it can be claimed by Bob, with his signature, but only after two weeks have passed if the trade has failed and Bob wants to return his funds. 

Next, Alice creates a Litecoin transaction, “locking up” 350 LTC. The 350 LTC locked up in this transaction can be unlocked in a follow-up transaction in two ways as well:

  1. Bob can claim the LTC with his signature and the secret value. 
  2. Or, it can be claimed by Alice, with her signature, but only after a week has passed.

This means that Bob can now claim the 350 LTC since he does know the secret value. He must do it within a week because Alice can claim her 350 LTC back.

  • Once Bob does claim the 350 LTC using a follow-up transaction, he broadcasts the secret value into the Litecoin blockchain.
  • Alice keeps an eye on the Litecoin blockchain to find the secret key and use it to claim the Bitcoin on the Bitcoin blockchain. 
  • Bob can only claim the 100 Litecoin if he reveals the key to his Bitcoin; therefore, a trustless trade is made.

Advantages of atomic swaps

There are several advantages to using atomic swaps:

  • They are trustless, meaning neither party must trust the other party to complete the exchange.
  • They are decentralised, meaning that there is no central authority that can control or censor the exchange.
  • They are secure, as they are protected by cryptography.
  • They are efficient, as they do not require the use of a third party.
  • They are future-proof, as they can be used to exchange cryptocurrencies on different blockchains and layer two protocols.

Disadvantages of atomic swaps

There are also a few disadvantages to using atomic swaps:

  • They can be complex to set up and use.
  • They have yet to be widely supported by exchanges and wallets.
  • They can be slow, as they rely on the confirmation of blockchain transactions.
  • They can be expensive, as they require the use of on-chain fees.
  • They can result in creating an MEV market where trades are front-run on-chain. 
  • If you’re conducting atomic swaps with altcoins, you expose yourself to liquidity and censorship risks.
  • Time delays of funds being locked up for weeks render trades inefficient.
  • A limited number of compatible assets are available for atomic swaps.
  • Since atomic swaps occur on the blockchain, fiat-to-crypto and crypto-to-fiat swaps are impossible, so you would need to acquire some Bitcoin, altcoin or a stablecoin.

The future of atomic swaps

Atomic swaps have the potential to revolutionise the way funds are exchanged without the need for these large entities we see dominate the space today. By removing the need for trusted third parties, atomic swaps can make DEFI more secure, efficient, and accessible.

As the adoption of Bitcoin continues to grow, atomic swaps are likely to become more widely used as more liquidity needs to move between various layers and networks. 

As atomic swaps technology matures, we should see increased adoption among decentralised exchanges, routing protocols and wallets so users can interact with it from a simple GUI. 


Do your own research.

If you want to learn more about Atomic Swaps for Bitcoin, use this article as a jumping-off point and don’t trust what we say as the final say. Take the time to research, check out their official resources below or review other articles and videos tackling the topic.

Disclaimer: This article should not be taken as, and is not intended to provide any investment advice. It is for educational and entertainment purposes only. As of the time posting, the writers may or may not have holdings in some of the coins or tokens they cover. Please conduct your own thorough research before investing in any cryptocurrency, as all investments contain risk. All opinions expressed in these articles are my own and are in no way a reflection of the opinions of The Bitcoin Manual

Leave a Reply

Related articles

You may also be interested in

Spark Explained

What Is Spark?

I’ve had a bit of L2 fatigue this past year and a bit, with everyone and their grandma getting a couple of VC seed round

withdraw phishing email scam

What Are Withdrawal Email Phishing Scams?

The rise of cryptocurrencies has brought about numerous investment opportunities, and capital has gradually flowed into it over the last decade, turning Bitcoin into a

Cookie policy
We use our own and third party cookies to allow us to understand how the site is used and to support our marketing campaigns.