Overview
An atomic swap allows two parties to exchange different cryptocurrencies directly, without relying on a trusted third party such as an exchange. The word "atomic" means the swap is indivisible: it either completes fully for both parties or does not happen at all. This eliminates counterparty risk.
How It Works
Atomic swaps rely on hash time-locked contracts (HTLCs), which combine cryptographic hash locks with time-based expiration conditions.
Step 1: Alice creates a secret (S) and its hash H(S)
Step 2: Alice locks her BTC in an HTLC on the Bitcoin chain
Condition: Bob can claim with S, or Alice refunds after timeout T1
Step 3: Bob sees Alice's HTLC and creates a matching HTLC
on the other chain using the same H(S)
Condition: Alice can claim with S, or Bob refunds after timeout T2 (T2 < T1)
Step 4: Alice claims Bob's coins by revealing S
Step 5: Bob uses the now-revealed S to claim Alice's BTC
Alice Bob
────── ──────
Lock BTC ──────────────────→ Sees HTLC
Lock ALT
Sees HTLC ←────────────────
Claim ALT (reveals S) ─────→ Learns S
Claim BTC
Requirements
Both blockchains involved must support the same hash function and have the ability to create time-locked contracts. Bitcoin's scripting language natively supports the opcodes needed for HTLCs.
Limitations
Atomic swaps require both parties to be online during the exchange process and currently have limited liquidity compared to centralized exchanges. Finding a counterparty willing to swap at an agreeable rate remains a practical challenge, though protocols like submarine swaps have extended atomic swaps to work between on-chain Bitcoin and the Lightning Network.