Atomic Swaps Explained: A Guide for Beginners

Atomic Swap

“Atomic swaps” might sound like something you’d hear about in a sci-fi movie, but they’re actually an increasingly common occurrence in the cryptocurrency space.

 If you’ve heard this term regularly but are still unsure about what exactly an atomic swap involves, I’ve written this guide for beginners to clear things up. Here, we’ll discuss what an atomic swap is, how they work and the benefits of them – so you can get a clearer grasp on how the concept is revolutionising how we trade cryptocurrency.

What is an atomic swap?

An atomic swap is also known as a “peer-to-peer swap” or “atomic cross-chain trading”. In short, it involves a trade of different cryptocurrencies on distinct blockchains, between two users. The transaction runs on smart contracts (wallet-to-wallet) and doesn’t require an intermediary or middleman to complete.

Both users do not need to trust each other to execute an atomic swap. This trustless exchange protocol was initially developed in 2012 by Sergio Demian Lerner, although many other developers have since experimented with peer-to-peer swaps. Before their introduction, it was incredibly difficult to trade different cryptocurrencies. That’s because the process involved multiple transactions and took time, and the market’s volatility meant that users didn’t always receive the kind of value they expected.

But where does the term “atomic” come from? This simply refers to the fact that transactions either happen in their entirety (i.e. are completed) or they don’t happen at all. If either party is unable to complete their side of the trade for whatever reason, it is cancelled and funds are automatically returned to their original owners.

Today, atomic cross-chain trading continues to grow in popularity, thanks to the high levels of security it offers to users that want to exchange their coins or tokens for other cryptocurrencies.

How do atomic swaps work?

There are two distinct ways that atomic swaps can be performed: 

1.    On-chain atomic swap: This involves the cross-chain trading that is directly executed between two blockchains and two different native coins. It offers the highest level of security because the transaction occurs on the blockchain itself.

2.    Off-chain atomic swap: This kind of atomic swap takes place on the secondary layer, and is usually based on bidirectional payment channels. They happen faster but are more complex to perform and may require more development until they’re fully implemented.

Atomic swap protocols are designed so that neither party can cheat. They work by one party depositing their coins (e.g. Litecoins) into a contract address, which acts as a safe. Once this safe is created, a key is generated and the user can share a cryptographic hash of this key with the second user. The second user is able to use this hash to create another contract address, where they deposit their own coins (e.g. Bitcoin). Remember, at this point, the second user only has access to the hash and not the key, so they can’t take those Litecoins (LTC) just yet.

Once the Bitcoin has also been deposited, a function known as “hashlock” is carried out. This enables each user to claim the other user’s cryptocurrency, by signing a transaction for the sender’s contract address. When the first user signs the contract, both are able to unlock the value of the currency they want, and the trade is complete.

What are the benefits of atomic swaps?

Simply understanding how atomic swaps work gives us some insight into the unique advantages this type of trade offers. However, let’s take a deeper look into why peer-to-peer swaps are becoming even more popular. 

     Users aren’t required to disclose their private key at any point. Users always own their own private keys and never have to give up control of their funds to a third party.

     It is the most secure type of digital asset trading. The “atomic” element to this trade means that users either get the funds they want in full, or nothing happens at all and funds are returned to their original owners.

     Atomic trading is cheaper than centralised exchanges. Most centralised exchanges charge a relatively high fee in addition to a withdrawal fee. Atomic swaps, on the other hand, just include a small transaction fee or none at all.

     Users can trade different cryptocurrencies. This is the first practical way to exchange between a variety of coins and tokens.

     No trust is required. Due to their decentralised nature, cross-chain swaps are possible without the need for an intermediary – so security is strong and both parties do not need to trust each other.

     Fast trades. Swaps can happen quickly with higher degrees of interoperability (different blockchains are compatible with each other, and intermediary coins are not needed).

To find out more about the rise of cross-chain trading and how it could benefit you or your business, just send me a message and I’d be glad to help.