An atomic swap is a smart contract technology that enables one cryptocurrency to exchange for another—without using an intermediary. Sounds good, right? If atomic swaps allow us to swap one cryptocurrency for another, why even use an exchange to begin with? Here’s what you need to know about atomic swaps.
What Is an Atomic Swap?
An atomic swap is a peer-to-peer exchange of one cryptocurrency to another. The atomic swap cuts out the need for expensive (and trust-based) third-party services, like an exchange, and lets people deal with each other directly.
The first atomic swap took place on September 20, 2017, between Decred and Litecoin.
— Decred (@decredproject) September 19, 2017
In its current guise, swapping cryptocurrency is time-consuming. You need an exchange with the correct tokens. You need to make sure that the exchange is secure. After which, you have to wait for transactions to process while paying expensive exchange transaction fees. For the majority of people, and especially if crypto is to continue expanding as a realistic form of currency, exchanging must be less challenging and less convoluted.
The atomic swap, then, presents a method for two (or more!) parties to exchange cryptocurrency within a specified timeframe. To make sure the transaction completes, atomic swaps use something known as Hash Timelock Contracts (HTLC). An HTLC is a form of smart contract with an inbuilt timer.
An Atomic Swap Example
Let’s use an atomic swap example.
- Alice has 50 Bitcoins. She wants to trade with Bob.
- Bob has an equivalent amount of Litecoin. He wants to trade with Alice.
- They open a payment channel.
- Alice deposits her Bitcoin and adds a value. The value acts like key and generates a unique hash that encrypts the entire process. Alice sends the unique hash to Bob.
- Bob deposits his Litecoin.
- Alice can unlock the Litecoin deposit. When Alice signs for the Litecoin deposit, Bob receives the value.
- Bob signs for the Bitcoin deposit.
Within this process, both Alice and Bob agree on a timeframe for delivery of the unique hash and to sign the transactions off. If either party misses the agreed timeframe, deposits return to their owners.
What is an atomic swap payment channel? In the example, you’ll see the step where “they open a payment channel.” There are two types of payment channels: on-chain and off-chain.
On-Chain Payment Channels
The first atomic swap between Decred and Litecoin was an on-chain atomic swap. An on-chain atomic swap takes place on the blockchain of either cryptocurrency. But the on-chain payment channel must meet a few requirements:
- Support for HTLC
- Branched transaction scripts
- Use the same hash algorithm
- Signature checks in transaction scripts
Decred and Litecoin are Bitcoin forks. Therefore, they share much of the same infrastructure, meeting the on-chain atomic swap requirements.
Off-Chain Payment Channels
Off-chain payment channels allow the participants to communicate directly, conducting their transactions as they would normally occur on their respective blockchains. Removing the transaction from the regular blockchain into a private snippet drastically decreases the time it takes to process the transaction. Very briefly, here’s how the off-chain payment channel works:
- The blockchain segment that the transaction will use is locked using a multi-signature arrangement or another smart contract format, while
- The participants conduct their transaction without submitting the details to the blockchain miners, then
- Each transaction adds to the blockchain once the transaction is finalized.
Off-chain payment channels are generally considered “Layer 2” protocols, in that they build on the existing blockchain to extend functionality. A prime example of an off-chain Layer 2 protocol is the Lightning Network. Check out Joe’s Lightning Network explainer for more information.
The Pros and Cons of Atomic Swaps
Atomic swaps sound great, but they’re not without limitation. Like all things, they have pros and cons.
The main advantages of atomic swaps are:
- Easier to process transactions between parties without relying on a third party. Reduces fees, as well as exposure to unfair transaction fees.
- Embrace decentralization by facilitating peer-to-peer transactions.
- Facilitating transactions between myriad tokens reduces disparity in the cryptocurrency ecosystem.
- Theoretically increases security; centralized exchanges are a vulnerable target.
The main disadvantages of atomic swaps are:
- Current uptake is slow, with very few exchanges attempting to incorporate atomic swaps.
- Difficulties between algorithms, as well as the need for HTLC or an equivalent.
- In its current guise, atomic swaps are slow; rather, the current system cannot cope with large volume (this will change with time though).
Atomic swaps are important. With time, atomic swaps, along with other advanced blockchain technology, will alter how we use cryptocurrencies in our daily lives.
3 Exchanges That Use Atomic Swaps
The overall uptake on atomic swaps remains relatively low. The major issue facing the atomic swap is that it runs against the grain for established centralized exchanges. These are the exchanges with the largest number of users. However, decentralized exchanges are increasing in popularity.
Decentralized exchanges (DEX) operate without a centralized authority and for many crypto advocates resemble a closer vision of how the cryptocurrency ecosystem should work. It should come as no surprise then that the decentralized exchanges are leading the way with atomic swap integration.
Here are three DEXs where you can use atomic swaps!
Komodo is one of the prime innovators for atomic swaps, with lead developer jl777 writing some of the code leading to the very first atomic swaps.
The Komodo exchange developed BarterDEX, an atomic swap powered decentralized exchange. The exchange suddenly brought atomic swaps to thousands of users. Since then, Komodo has taken atomic swap from strength to strength. By July 9, 2018, Komodo had performed over 110,000 atomic swap transactions as well as supporting a huge number of tokens.
Blockchain.io is taking a different route from the Komodo decentralized exchange implementation. Blockchain.io implements a mixture of centralized and decentralized technology to “make atomic swaps simpler, easier, and more efficient to use.” There are a few clear differences.
For instance, the Blockchain.io order remains centralized but retains the option to trade using an atomic swap. Coins never deposit directly to Blockchain.io, instead using a secure escrow smart contract to lock the coins into the atomic swap transaction. The Blockchain.io atomic swap process does differ to the one detailed above. Read more about the Blockchain.io Decentralized Settlement process.
Blocknet is different again, in that it is a decentralized application platform that also features inter-blockchain functionality, creating strong links between the numerous blockchains. Blocknet is considered a Layer 2 blockchain protocol, extending blockchain and cryptocurrency functionality for users.
Blocknet is interesting in that it bills itself as “The internet of Blockchains.” Blocknet’s XBridge “blockchain router” allows peer-to-peer cross-blockchain connections. The XBridge facilitates cross-chain atomic swaps, as well as cross-chain smart contracts. Also, Blocknet’s Block DX decentralized exchange has great UI and an extensive list of coin pairs.
Want to learn more about cryptocurrencies? Check out Dan’s list of the best cryptocurrency podcasts.