Skip to main content

Glossary · Definition

Atomic Swap

An atomic swap is a trade of coins between two people on different blockchains that either completes fully for both sides or does not happen at all, with no exchange holding the funds in between. It is like a pair of linked lockers that open for both people at once and return the items if either side does not follow through.

In simple terms

An atomic swap is a trade of coins between two people on different blockchains that either completes fully for both sides or does not happen at all, with no exchange holding the funds in between. It is like a pair of linked lockers that open for both people at once and return the items if either side does not follow through.

Definition

A peer-to-peer exchange of assets across two blockchains, enforced by hashed timelock contracts so that both transfers complete or neither does.

In depth

An atomic swap uses hashed timelock contracts on both chains, locked to the same secret hash. The initiator creates a secret, locks funds on the first chain so the counterparty can claim them with that secret, and sets a refund after a longer timeout. The counterparty locks funds on the second chain against the same hash with a shorter timeout. When the initiator claims on the second chain, the secret becomes public there, and the counterparty uses it to claim on the first chain. Both chains must support compatible hash functions and timelocks, both parties must stay online to act in time, and the party holding the secret can abandon the swap if prices move.

What does Atomic Swap mean?

Two people agree to trade, for example bitcoin for litecoin. The first person creates a random secret, locks their bitcoin in a contract that pays the second person on presentation of the secret, and sets a refund after two days. The second person locks their litecoin in a contract using the same hash that pays the first person on presentation of the secret, with a refund after one day. The first person claims the litecoin, which publishes the secret on that chain. The second person copies the secret and claims the bitcoin.

An example

Someone trades 0.01 BTC for 1 LTC with a stranger they met on a peer-to-peer platform. Each locks their coins in a hashed timelock contract, paying about $2 in fees on each chain. When the first person claims the litecoin, the secret is revealed, and the stranger uses it to claim the bitcoin. If either side had failed to follow through in time, the timelocks would have returned the coins to their original owners.

Figures are illustrative only.

What beginners get wrong

  • Many people think atomic swaps are instant. Each step needs confirmations on both chains, and the whole process can take from minutes to hours.
  • It is easy to assume an atomic swap removes every risk. A party who goes offline and misses a claim deadline can lose out, and the side holding the secret can walk away if prices move.
  • Some users believe any two blockchains can be swapped this way. Both chains need compatible hash functions and timelock support, which rules out some pairs.

CryptoBipto is an education platform that teaches how cryptocurrency works. You cannot buy, sell, send or store cryptocurrency on CryptoBipto, and it does not hold anyone’s money or keys, carry out trades or give financial advice. Paper trading on CryptoBipto uses simulated money only. CryptoBipto will never ask for your seed phrase or private key. Read our standards

Keep exploring the language.

Part of How does a blockchain transaction actually work?, the subject page for blockchain mechanics, with all 173 of its definitions in one place.