1. Learn Center
  2. Crypto Next Level
  3. How to Exchange Different Cryptos Using Atomic Swaps

How to Exchange Different Cryptos Using Atomic Swaps

09/04/2023
7 Minute Read

Centralized crypto exchanges (CEXs) are a crucial aspect of the current crypto market. Although there are other ways to swap digital assets, CEXs have the highest liquidity in the industry. Big crypto exchanges such as Coinbase and Binance even have intuitive UI/UX (user interface/user experience), making it easier to trade between fiat and crypto

Although CEXs make crypto trading simple, they come with a few drawbacks. Most notably, CEXs have complete ownership over the crypto on their trading platforms. Unless users take their crypto off a CEX, there’s a risk of the exchange going bankrupt or abruptly freezing their accounts. Also, CEXs charge transaction fees and ask for users’ personal information. 

And to reduce overreliance on CEXs, some developers have begun using blockchain technology to “decentralize” crypto transfers. One recent innovation in this field is an “atomic swap.” By using encoded smart contracts, atomic swaps promise to eliminate the need for a third-party custodian when trading cryptocurrencies on separate blockchains. Atomic swaps are highly experimental, but they could soon revolutionize crypto trading.

What are atomic swaps?

An atomic swap is a crypto transfer that relies on smart contract technology. First introduced on Ethereum (ETH), smart contracts are pre-programmed commands that fulfill their tasks once certain conditions are met. Web3 developers use smart contracts to remove the need for central authorities in their dApps (decentralized applications), as a reduced number of intermediaries makes the process smoother. 

In an atomic swap, two parties agree to create a smart contract where they place the crypto they want to transfer. This smart contract generates special “passcodes” both parties can use to deposit and unlock the crypto. These interactions take place on the blockchain without the aid of order books or a third-party custodian. People with a compatible crypto wallet or who use an atomic swap exchange such as Komodo can take advantage of these trustless peer-to-peer (P2P) crypto swaps without sharing KYC info

The word “atomic” refers to the “atomic state” in computer programming, wherein programs execute or fail—there’s no third option. So when people enter into an atomic swap, there are only two possibilities: the transaction will work, or they’ll get a full refund. 

Atomic swaps first gained prominence in 2017 when Litecoin’s founder, Charlie Lee, announced he used this technology to exchange LTC for the altcoin Decred (DCR). Shortly after this first recorded atomic swap, Lee announced another successful transfer between LTC and Bitcoin (BTC).

What are HTLCs, and why are they important?

Hashed Timelock Contracts (HTLCs) are a type of smart contract people use to make an atomic swap. These specialized contracts hold all deposited digital assets and transfer coins to each individual’s associated wallet address. 

HTLCs also generate two “keys” for each swap participant to unlock crypto. The “HashLock Key” lets users deposit and redeem crypto in the HTLC, while the “TimeLock Key” provides extra security. If one person doesn’t meet the requirements of their atomic swap contract within a pre-set amount of time, the TimeLock Key will redistribute any crypto put into the HTLC.  

Example of atomic swap

Suppose Alice and Joe want to use a crypto atomic swap to exchange 1 BTC for an equivalent amount of ETH. At the time of writing, the exchange rate between BTC and ETH is 1 BTC for every 13.75 ETH. To make this trade happen, Alice and Joe need crypto wallets that support atomic swap functions. Once they’ve set up their wallets, the process of an atomic swap typically follows the same pattern:

  1. Alice and Joe generate an HTLC with a pre-set timeframe for the transaction. 
  2. Alice deposits 1 BTC, and the smart contract automatically creates a new password known as a “preimage.”
  3. Joe receives the preimage and uses it to deposit his 13.75 ETH into the HTLC.
  4. Alice and Joe need to use their HashLock Keys to transfer the crypto they want into their wallets.
  5. If Alice or Joe fails to unlock the crypto within a certain time frame, the smart contract will send their initial deposits back to their wallets. 

Pros and cons of atomic swaps

Atomic swaps are an attractive option for those who don’t feel comfortable entrusting their crypto to CEXs. However, since atomic swaps are relatively new, there are a few concerns crypto traders should know before using them.

Pros

  1. Offers complete control over crypto: Atomic swaps are P2P crypto transfers that use smart contracts as an unbiased escrow service. There’s no need to trust a CEX to watch over your crypto when making these trades since the funds will go directly into your self-custodial wallet.
  2. Facilitates cross-blockchain transfers: When you want to trade between altcoins on different blockchains, you typically need to convert digital assets to fiat before buying another coin. Atomic swaps facilitate the direct exchange of digital currencies, even if they have low liquidity or limited trading pairs on CEXs.
  3. Prevents counterparty risk: Since HTLCs run on a timer, they won’t complete a transfer if both parties don’t fulfill their obligations. The TimeLock feature ensures both parties either get a refund or receive their desired cryptocurrency, provided they use an atomic swap.
  4. Doesn’t charge commission fees: Atomic swaps only charge standard network fees for whatever cryptocurrency you’re transferring. You won’t have to pay additional trading, withdrawal, or commission fees as you would on a CEX. 

Cons

  1. New and largely untested technology: Although there have been many successful atomic swaps, this technology is still experimental. There are concerns over hacks, bugs, and the reliability of HTLCs. It may take a few years before blockchain developers perfect atomic exchange technology.
  2. Not compatible with every crypto: Theoretically, atomic swaps should be able to process transfers between any two cryptos. At this point, however, atomic swaps are closely associated with established coins such as Bitcoin, Ethereum, and Litecoin. It may take time before developers figure out how to securely transfer lesser-known altcoins using atomic swaps.
  3. Complicated and not easily accessible: If people aren’t familiar with cryptocurrencies, it’ll be difficult to explain how to use atomic swaps. It’s also tricky to find reputable crypto wallets and websites that use atomic swap technology.
  4. Lack of fiat on-ramps: People who don’t already own cryptocurrency can’t use atomic swaps to trade fiat currencies for digital assets. Until atomic swap services integrate with bank accounts or debit cards, people without crypto need to rely on CEXs.

Are there any alternatives to atomic swaps?

Atomic swaps aren’t the only way crypto users can exchange tokens without relying on a centralized platform. The rise of DeFi (decentralized finance) in 2020 has unleashed a few alternative ways of sending tokens throughout Web3. 

  1. Decentralized exchanges (DEXs): Like atomic swaps, DEXs use smart contracts to offer trustless P2P crypto transfers. However, DEXs aren’t used for just one crypto transfer between two parties. Most DEXs allow anyone to deposit crypto into “liquidity pools” that traders can use to buy and sell tokens with their wallets. Currently, most DEXs such as Uniswap only work on one blockchain, but new projects such as ThorChain can make decentralized cross-chain swaps a reality.
  2. Cross-chain bridges: Cross-chain bridges are portals where anyone can deposit crypto collateral to receive a copy of their tokens on another blockchain. Since most blockchains have closed-off ecosystems, cross-chain bridges allow people to use their crypto assets on competing chains. While cross-chain bridges are popular, they’re one of the most hack-prone areas of Web3 because they hold large reserves of crypto collateral.
  3. Interoperable blockchains: In crypto, “interoperability” means communication between competing blockchains. Blockchains such as Bitcoin and Ethereum have closed-off systems, making it challenging to transfer coins or tokens between projects. However, a few blockchains are focused on improving interoperability. If these projects succeed, it may become easier to naturally bridge cryptocurrencies. Two examples of interoperable blockchains are Cosmos and Polkadot.

Wrapping up

Atomic swaps may become a central feature in crypto’s future. While this technology has yet to go mainstream, it could reduce the influence of centralized trading sites. The more accessible atomic swaps become, the more opportunities crypto traders will have to exchange tokens without the risks and fees associated with CEXs. 

At Worldcoin, we aim to preserve anonymity and increase safety while using DeFi services such as atomic swaps. For instance, we’re currently using our eye-scanning Orb device to prove each crypto wallet has a unique owner without collecting KYC data. Subscribe to our YouTube channel to learn more.

Subscribe to the Worldcoin newsletter