Glossary / Lightning & layer 2
Atomic swap
- Definition
- An atomic swap trades coins on two different blockchains in a single all-or-nothing operation, enforced by matching hash locks and timelocks rather than by an exchange holding both sides.
Two chains, two contracts, one secret that unlocks both of them. Tier Nolan sketched the design on the Bitcointalk forum in May 2013, and the Decred team published the first working on-chain swap, Decred for Litecoin, on September 20, 2017. The appeal for a buyer is trading without depositing anything anywhere; the catch is that hardly anyone offers real liquidity this way.
How it works
An atomic swap rests on one secret and two clocks.
Say you are giving up bitcoin. You pick a random secret, hash it, and lock your bitcoin in a script that pays your counterparty if they present the secret, or refunds you after 48 hours. Your counterparty locks their coin on the other chain in a script with the same hash, refundable to them after 24 hours. You claim their coin by revealing the secret, which publishes it on that chain, and they read it there and claim your bitcoin. Either both legs settle or both refund.
The asymmetric deadlines are the safety mechanism, not a detail. The person who knows the secret must always face the earlier deadline, so that once they act the other side still has ample time to react. Reverse the two windows and the secret holder can wait for the counterparty's refund to become spendable and then claim both.
Not every chain can do this. Monero has no script system to hold a hash lock at all, so bitcoin to monero swaps use adaptor signatures instead: the signature that claims the bitcoin mathematically leaks the value needed to claim the monero. That protocol went live on mainnet in August 2021 after work by the COMIT team.
Two problems keep the technique niche. Both parties have to stay online for the whole window, which can run for hours. And the person holding the secret has been handed a free option: if the price moves while the clock runs, they can simply refuse to reveal it and take the refund, having risked nothing but fees.
Where you see it
Real atomic swaps live in a small set of tools, and a much larger set of services borrow the name without doing anything atomic.
BasicSwap and the community maintained UnstoppableSwap software are where bitcoin holders actually meet monero holders directly. Boltz uses the same hash and timelock machinery to move value between the bitcoin chain and Lightning. Meanwhile most websites advertising instant swaps are ordinary custodians: you send coins to their address, they send different coins back, and for the minutes in between they own everything. Changelly is the example we review, and the difference matters more than the marketing suggests.
Costs are the honest reason to think twice. You pay mining fees on both chains, twice over if the swap fails and both sides refund, and the quoted rate has to cover a counterparty's option risk. On amounts under a few hundred dollars, that stack of costs usually beats whatever you were trying to avoid.
Atomic swap vs decentralized exchange
An atomic swap is a private arrangement between two people across two ledgers, while a decentralized exchange is a public contract running on one. A DEX needs a smart contract platform, a pool of liquidity and a token standard, which is why the bitcoin traded on one is almost always a wrapped IOU issued by a custodian. An atomic swap has no pool, no contract deployed anywhere and no token: it moves genuine bitcoin, and it needs a specific human on the other end who wants exactly the trade you want, at the same moment.