A protocol that enables conversion of crypto-assets across multiple Blockchains without compromising your private keys and going through a third-party.
There are more than 1500 Cryptocurrencies out in the world. They flaunt various use cases and features, which brings us to the need of converting/swapping our crypto assets every now and then. Those who trade, hold or use cryptocurrencies know the jarring task of currency conversion.
Two widely adopted ways to convert the tokens are -
These third-party services are unsafe, centralized, and costs us a huge toll in transaction and network fee. The problems with the exchanges are -
We are all familiar with the hacks in centralized exchanges, $ 368M worth of BTC hack at Mt.Gox and the very recent $ 1M worth of ETH compromised at Bithumb are a few to mention. When making transactions or trading on exchanges, we entrust their software and teams operating behind them with our wallet’s private keys. Most of the crypto assets are kept in hot wallets by the exchanges, instead of the user account for better liquidity and faster transactions. However, this also makes it vulnerable to attacks. On top of it, KYC compliances take the anonymous part out of the equation.
Suppose, you want to convert your Ethereum token to Litecoin. You’ll go to an exchange to sell your Ethereum token for Bitcoin and use your newly purchased Bitcoin to buy Litecoin. In all the exchanges, the cryptocurrency is traded in pair with BTC, USDT, or ETH and to convert any of the tokens, you have to make at least one extra trade. In the entire process, you end up paying transaction and network fee and the price fluctuation makes it worse. Many times, people lose assets in the process because of the price fluctuations.
Though the most adopted trading pairs provide better liquidity, the high number of transactions puts a load on the network. It increases the network fee and thousands of small transactions get stuck in the execution pipeline. In the case of Bitcoin, it takes hours and days to receive your funds in the wallet. Network congestion is a challenge for DEXs (Decentralized Exchanges) too. Imagine, you want to purchase fruits and instead of getting it directly from the local vendor, you place your order in a global market where millions are waiting in a line.
The right way to swap or convert your cryptocurrency would be to settle the transactions securely off-chain or on-chain, peer-to-peer, instead of going through a centralized exchange. To make this a reality, there exists a faster, cheaper, and better way to convert your holdings from one to another token, which is called Atomic Swap. This blog speaks of how it works, the benefits, and wallets that support this feature.
Atomic Swap is a smart contract enabled technology that gives you the ability to exchange digital assets seamlessly. Now you might think, what about decentralized exchanges? Atomic swap is different in a way that it is a wallet-to-wallet transaction and processed via an encrypted cryptographic protocol with zero default risk. The participating users in a transaction send their funds to a hashed timelock contract (an off chain state channel), the fund transfer happens instantaneously with a guaranteed refund in case the other party declines or the transaction fails for some reason.
Why Atomic Swap technology is such a big thing? The individual Blockchains operate under different consensus algorithms and protocols, making cross-chain transactions a hard algorithmic problem. The interoperability of Blockchains is a huge concern and a hurdle in the way of mass adoption. But with the wallets equipped with Atomic Swap, tokens powered by various Blockchains can be exchanged in real time.
By definition, Atomic transactions are when two parties exchange funds and both the transactions either succeed or fail. Atomic swap enables fund transfer/conversion without the need of a centralized third-party such as an exchange or escrow. TierNolan proposed an algorithm in 2013 to carry a swap or transaction between two parties using an alt-chain that we now know as Atomic Swap.
If you are interested in learning the nitty-gritty of the process, this part is for you.
Atomic swaps are executed via Hashed Time Lock Contracts (HTLC). This special form of off-chain payment method saves you from clogging in the pending transactions on the main network and transfers the fund in real time. HTLC is a time-bound transaction between two parties.
This is how the algorithm works -
Alice picks a random number x
1. Alice submits TX1 to the network
Bob creates TX3: "Pay v alt-coins to < A-public-key > if (x for Hash(x) known and signed by Alice) or (signed by Alive & Bob)"
Bob creates TX4: "Pay v alt-coins from TX3 to < Bob's public key >, locked 24 hours in the future, signed by Bob"
Bob sends TX4 to Alice
Alice signs TX4 and sends back to Bob
2. Bob submits TX3 to the network
3. Alice spends TX3, revealing x
4. Bob spends TX1 using x
After 3: Transaction is completed by 2
- Alice must spend his new coin within 24 hours or Bob can claim the refund and keep his coins
- Bob must spend his new coin within 72 hours or Alice can claim the refund and keep his coin
For safety, both should complete the process with lots of time until the deadlines. This cryptographic explanation is tricky, so here is a plain English version:
Alice and Bob are exchanging BTC and alt-coin. TX1 and TX2 are two transactions of BTC created by Alice with her and Bob's public key. A second transaction is a contract that will execute itself after the lock-in period of 48 hours if Bob refuses to send the alt-coins or the transaction fails for some reason. This way, either both the transactions go through or both fail, that's what makes it an Atomic Swap. Alice creates the value and generates its hash which is used to create the contract address and deposits her tokens there. She then sends the hash to Bob. Bob then generates the contract address through the hash and sends his tokens there. In order to get her hands on Bob’s tokens, Alice will have to unlock the address by using her value. Upon unlocking and getting her coins, the value of the key is exposed to Bob. Bob then uses the value to get his coins.
Today, a bunch of decentralized exchanges provide the capability of Atomic Swap: Lighting Labs, Altcoin.io, Komodo, & 0x are some of them.
This was the first project which implemented inter-operability between Bitcoin and Ethereum. They first performed the swap between ETH and DOGE-coin. Komodo charges 0.15% Atomic Swap fee to make the transfers. Users need to place an order on its DEX, BarterDEX.
Lightning Labs is building an open protocol layer that uses smart contracts to make peer-to-peer transactions available to anyone. They are also among the first to develop Atomic Swap solution for tokens from various Blockchain.
As it requires widespread adoption, atomic swap technology still has a long way to go before it could present a threat to the centralized exchanges. Exchange operators should not take it lightly though. The atomic swap algorithms are around for a few years now but the market is still only months old — and it continues to innovate rapidly.
Lack of scalability and interoperability are among the biggest challenges that the crypto/Blockchain space is facing. With atomic swaps, we have a way to solve two problems in one go. This technology has the potential of taking us to the next phase of crypto transactions. While the mainstream news outlets focus more on covering the price volatility of bitcoin, most of the achievements taking place in the cryptocurrency world are underreported and misunderstood. Atomic swaps are one of the innovations that belong to this category.