Atomic Swap

A direct exchange of coins between two blockchains that either completes fully or does not happen at all.

What is an Atomic Swap?

An atomic swap is a way for two people to exchange cryptocurrencies that live on different blockchains without trusting each other or a third party. "Atomic" means the trade is all or nothing: either both transfers happen or neither does.

How it works

Most atomic swaps use hashed timelock contracts (HTLCs). The idea rests on two locks:

The first party creates a secret and locks coins on chain A under its hash. The second party locks coins on chain B under the same hash, with a shorter deadline. When the first party claims the coins on chain B, the secret becomes public on that chain, and the second party uses it to claim the coins on chain A.

Example

Two users agree to swap bitcoin for litecoin. Each locks their side in an HTLC. Once the first user reveals the secret to collect the litecoin, the second user reads it from the blockchain and collects the bitcoin. If either user walks away, both refunds unlock after the deadlines pass.

Why it matters

Atomic swaps remove custody risk from a trade: neither side has to deposit coins with an exchange or hand them over first. They are a building block for decentralised exchanges and for payments routed across the Lightning Network.

Limits and risks

Both chains must support compatible hash functions and time locks. Each party has to stay online or have software watching for the deadlines. Swaps involve several on-chain transactions, so they can be slower and incur more fees than a trade on a centralised exchange, and a counterparty can still waste time by never completing their step.

Related terms