Type to search

101 Spotlight

What are atomic swaps?

atomic swaps

Cross-chain atomic swaps are the last word in secure peer-to-peer crypto trading: a means of exchanging tokens across blockchains, completely trustlessly. Here’s how it works.

Centralised exchanges have proven woefully inadequate, a single point of failure for decentralised crypto protocols. DEXs are an improvement on this, but most only work within their own ecosystem: you can only exchange ERC20 tokens and ETH against each other, for example, or Waves tokens against each other. Some offer coin ‘wrapping’, with coins locked and traded as proxy tokens on the DEX, but this comes with varying levels of complexity, security and centralisation.

Atomic swaps are a way of exchanging coins or tokens completely trustlessly across blockchains. They are called ‘atomic’ because the exchange either happens completely, or not at all – there are no partially-filled orders. Here, in outline, is how it works:

  • Alice and Bob want to trade BTC for LTC. Alice is selling 1 BTC for Bob’s 50 LTC.
  • Alice generates a secret phrase – essentially just a large, random number.
  • She hashes this secret phrase.
  • Alice now creates a transaction using a smart contract on the Bitcoin blockchain, with the conditions that 1 BTC will be transferred to Bob’s address when the secret phrase (pre-image) of the hash is provided.
  • Bob creates a transaction on the Litecoin blockchain using the same hash. He arranges to transfer 50 LTC to Alice’s address when the secret to the hash – which he does not currently know – is revealed.
  • Once Bob has created his transaction, Alice reveals the secret phrase. She can now transfer Bob’s LTC to her. Since the phrase is publicly revealed on the blockchain as part of this process, Bob can transfer Alice’s 1 BTC to his address.
  • Further conditions can be applied within the smart contract. For example, there may be a time limit on the contract, to prevent coins from being locked indefinitely if the other party does not create their conditional transaction.

Exchanges based on true atomic swaps are the Holy Grail of DEX implementations: a means of trading different coin pairs, completely trustlessly and anonymously, with no third parties or centralised organisations required at any stage.


You Might also Like