63. Atomic Swap: What is an atomic swap, and how does it work with cryptocurrencies?

Atomic swaps are also known as cross-chain atomic swaps. It is nothing more than a swap of cryptocurrencies from separate blockchains. The rotation is carried out between two separate blockchains without third parties being involved. The basic idea of this process is to eliminate centralized intermediaries such as exchanges and give owners complete control over their tokens.

The term ‘atomic swaps’ itself is derived from the words ‘atomic state’. It refers to a state where there is no substrate – whether it happens or not. The analogy is a cryptocurrency transaction – either it happens or it does not.

It probably will not surprise you that most cryptocurrency wallets or blockchains that support atomic swaps use smart contracts to do this. Contracts are programs within blockchains that are executed when certain conditions are met. What conditions do we have in the case of atomic swaps? Each party agrees to a certain transaction before a certain timer expires. Smart contracts in this case also prevent cryptocurrencies from being stolen by one of the parties.

Atomic Swaps: a definition?

Every cryptocurrency is backed by a particular blockchain. It is designed to accept transactions in specific tokens or cryptocurrencies. For example, we cannot transfer Bitcoin (BTC) directly to the Ethereum blockchain (ETH). We first have to make a conversion to one fiat currency, buy another and make many more conversions. As a result, we get the desired cryptocurrency. However, the whole process is time-consuming and tedious. Atomic Swaps allow us to exchange cryptocurrencies from different blockchains in a single transaction.

For example, decentralized exchanges (DEXs) can perform such a swap for us. DEXs are platforms where we trade without the involvement of a third party. For such exchanges, we can also use cross-swaps, where we transfer digital assets to another wallet, perform the exchange there and then transfer the assets back.

How do Atomic Swaps work?

The process itself is very interesting. Two token holders agree to swap their tokens for an amount they agree between themselves. The smart contract responsible for this swap sees this and performs the transaction for them. This exchange is recorded in the blockchain and approved by the nodes of the respective network. A new block is then opened for the next transaction.

What is very important in this case – this transaction cannot be undone. Both parties must agree to a new swap if they want to exchange tokens again or have them back.

Atomic swaps use so-called Hash Timelock Contracts (HTLC) in the way they work. This automates the exchange of digital assets. HTLC is a time-limited smart contract that generates a single, cryptographic hash at each end of the page. In addition, participants in the transaction must confirm receipt of the funds within a certain time frame. If one party does not confirm the transaction, it is declared invalid and the funds are returned. This eliminates the risk of one of the parties misappropriating the funds in question.

Example. Kasia wants to swap her 0.5 BTC with Peter for an equivalent number of XRP. So, she orders such a transaction via a wallet that supports atomic swap. The cryptographic function automatically generates a haxadecimal number with which the transaction is encrypted. The whole process is repeated on Piotrek’s side.

Kasia and Piotr then release their funds using their encrypted numbers. This must be done within a certain time frame, otherwise the transaction is invalid.

Why are atomic swaps so important to the digital asset ecosystem?

Atomic swaps solve one of the fundamental problems. We are talking about the inefficiency of exchanging cryptocurrencies via centralized finance (CeFi). For example, anyone who wants to exchange BTC for LTC via CEX has to:

  • Set up an account on a platform that supports the BTC/LTC pair.
  • Send BTC to the exchange.
  • Convert BTC to LTC and pay an additional transaction fee.
  • Then send LTC to your wallet and pay another transaction fee in addition.
  • Next, you have to wait for the exchange to process the transaction. Again, you do not get beyond the transaction fees.

Therefore, you can see how time-consuming and expensive this process is. In addition, CEXs often have a security problem regarding the funds stored. And why? Because our assets are stored in so-called custody wallets, and the private keys of these wallets belong to the exchange. As a user, you do not have ful control over your assets. In the event of a cyber-attack, your cryptocurrencies stored on this wallet could be at risk.

Eliminating such a middleman eliminates costs and many other potential risks for digital asset users. Hence, the idea of atomic swaps. They are equally important for the growth of DeFi.

Advantages of Atomic Swaps

Significantly greater interoperability. Swaps open up the possibility of connecting different blockchains.

They are fully decentralized. They are based on three fundamental principles: programability, immutability and autonomy. With smart contracts and blockchains, users have full control over their wallet, their private keys and the cryptocurrencies stored in them.

They are cheaper than traditional transactions. And it’s all thanks to the fact that there are no middlemen. With some blockchains, fees are as low as a few cents.

Disadvantages of atomic swaps

They are a novelty in the cryptocurrency sector. Therefore, they are somewhat speculative. Their mechanisms are still in their infancy, so to speak, which means that the smart contracts or dApps that propose this solution have not been properly tested.

Their structure is very complex, so they are slow to catch on. The whole process needs to be more accessible and welcoming to the user. Developers still have a long way to go.

There are still a limited number of cryptocurrency pairs. Depending on what digital assets we want to swap, it may be easier for us to do it on a centralized exchange.

With Atomic Swaps, we do not have fiat currency trading. As they only exist on the blockchain, fiat-crypto and crypto-fiat swaps are not possible.


Atomic swaps are a good route to achieve high security, immutability and decentralization. With the development of Web3, swaps will become more accessible and encourage more and more interactions between chains.

It is also a great solution for efficient and decentralized transactions to develop and promote blockchain interoperability.

Sign up for the newsletter!

Receive the latest cryptocurrency news in your email every week.