Atomic Swaps. If you find your response to these 2 words being “what?” don’t worry, we’re about to break it down; a lot of things in the cryptocurrency space sound technical, but underneath the basic concept is actually pretty simple. Atomic Swaps are no different.

If you’ve read our guide on cryptocurrency exchanges, you’ll realise that exchanges are essentially a central third party, through which users can buy and sell various digital currencies (depending which ones the exchange you are using supports) in exchange for other digital currencies or major national fiats currencies. In real terms, on exchanges I can swap my bitcoin for Ethereum, my Ethereum for dollars, or my dollars for bitcoin.

The downside is, exchanges don’t do this for free. Like foreign currency exchanges, they charge a commission for the service. Since no one likes extra fees, finding a way to remove the need for exchanges from transacting would be optimal – but how? That’s where Atomic Swaps come in.

What are Atomic Swaps?

Atomic Swaps are direct exchanges between 2 sellers of cryptocurrencies. Through a peer-to-peer exchange of currencies, you can avoid third parties and their risks and fees. These trades can be done across blockchains with different coins (e.g. bitcoin for Litecoin) as well as through off-chain channels which are connected to the main chain.

The possibility has not been around for long; the first known successful completion of Atomic Swap took place on September 20th, 2017, when Decred and Litecoin successfully completed the process. But it was pretty exciting as it potentially opened up a significant number of possibilities through a safe transaction which allowed the users to keep complete control of their private keys throughout the process.

Atomic Swaps as a Concept?

Breaking it down, it’s simple.

Two people – Alice and Bob –want to trade. To do this, they must decide on a secret together. The secret will act as a verifier to make sure that each one gets what they agreed to. The trade can only be completed if the two parties have secrets which match. Obviously not a problem for Alice and Bob who have just agreed on one, but it will protect them from their coins being accidentally sent to Charlie, or if Charlie attempts to get in on the action and steal coins from either of them – he does not know the secret and therefore is locked out of the whole process. With the secret both of them know, Alice and Bob safely exchange coins with one another and they have nothing to fear from Charlie as a potential malicious third party.

That’s the concept. In reality, the process works through a Hashed Timelock Contract (HTLC) which we will turn to now.

Hashed Timelock Contracts (HTLCs)

These are a type of payment channel which exist off-chain. HTLCs are known as state channels and their purpose is to serve as a two-way communication channel for parties wishing to transact with one another.

The point is, transactions usually happen on-chain. Everything which happens on-chain needs to be validated by a miner or other third party. This takes time.

Use of an HTLC allows for transactions off-chain. Free from being forced to rely on a third party to complete your transaction, allows completion times to be dramatically increased from minutes to seconds.

Off-chain state channels can be opened when the participants who are transacting agree on it. A section of the blockchain becomes locked through a smart contract between the participants. The participants can then sign multiple transactions on this section of the chain without ever having to wait for miners to validate it, making it ideal for things like frequent, small transactions such as buying coffee or lunch. Once the pre-determined transaction value limit is reached or the pre-determined HTLC time frame comes to an end, the entire section is sent for validation and added to the chain.

Why is this relevant for Atomic Swaps? Well, the pre-determined time frame just mentioned can be set to even just five minutes or so. And using this in conjunction with the transaction value limit which the parties can pre-determine, users can create extremely specific transaction frameworks which will close themselves once the terms are fulfilled. This allows them to transact with each other without leaving themselves or the chain unnecessarily vulnerable to malicious attacks.

Concept to Reality

So, we talked about the secret which Alice and Bob know that enables them to carry out Atomic Swaps. But what does all of this look like in reality, behind the computer screen? I’ll use some analogies to help, such as lock, key and safe. These are the steps:

Firstly, Alice and Bob must decide they want to transact together. Let’s say Alice wants to swap 1 LTC with Bob for 1 BTC. Bob – being a little new to crypto – agrees. They both open a payment channel and one of them creates a contract address . Let’s say in this situation it was Alice, since she’s the more experienced one. The contract acts like a safe. Alice puts her 1 LTC inside and creates a value (the safe’s key ). So, there is a safe and a key so far – but no lock! But that’s fine – there is a key, so Alice can make a lock to fit it. The lock is made from the hash of the value . Alice sends a copy of the hash ( lock ) to Bob as well as lock ing her safe . Bob is able to generate another address ( safe ) by using the hash ( lock ) Alice sent him. He sends his 1 BTC to the address which was created using the hash. You could say Bob locks his safe with Alice’s lock. Alice, holding the value ( key) , is now able to unlock Bob’s safe, as it is locked with her lock. But in order to open Bob’s safe , she must complete the transaction and sign Bob’s contract address with the value. She can now go and collect her 1 BTC. Signing Bob’s contract address reveals the value and thus the key to Bob, who can now collect the contents of Alice’s safe , after also signing the transaction of course.

Pros and Cons of Atomic Swaps

Atomic Swaps are no doubt useful. As has been explained, they allow users to limit transaction costs and increase economic efficiency. They also mitigate the risk from hacks and theft which comes from using third-party centralised exchanges. Furthermore, Atomic Swaps are good for the crypto ecosystem. They increase the possibilities of interoperability between currencies and therefore increase the use value of crypto as a whole. It also increases the chances of diversification in portfolios allowing specialisation within cryptocurrencies not to mean they get relegated to a tiny niche of users, but rather can be used by many people for different things.

However, there are limitations. Right now, in order to make an Atomic Swap, each currency must use the same hash algorithm, as well as both being able to generate HTLCs. At this moment that massively limits their scalability. Until they become more flexible their growth will be limited. Whilst they may struggle to reach usability at this time, it is certainly only a matter of time before their functionality becomes more refined and wider adoption follows.

Image Credits: “NewMoneyReview, Flickr”