Atomic Swap
An atomic swap is a direct trade of coins between two different blockchains without an exchange or middleman. Hashed timelock contracts make sure either both sides get paid or both get refunds.
Swapping bitcoin for another coin usually means trusting an exchange to hold both sides. An atomic swap removes that middleman. Each party locks coins on its own chain in a contract tied to the same secret, and revealing the secret to claim one side automatically lets the other side claim too. If anything stalls, timeouts return the coins. This page walks through the protocol, the timing rules that keep it safe, and the practical catches that have kept it niche.
- Category
- Cryptocurrency and Blockchain
- Reading time
- 6 min
- Also called
- Cross-chain swap, Atomic cross-chain swap, Cross-chain atomic swap
- Updated
An atomic swap in plain words
An atomic swap lets two people trade coins they hold on different blockchains without a trusted third party or a central exchange.1 Simply sending coins to each other would not work, because whoever receives first could stop cooperating.1
"Atomic" means all-or-nothing: either both transfers happen or neither does.1 The tool that makes this work is the hashed timelock contract, which pays out to whoever reveals a secret before a deadline and otherwise refunds the sender.2 See Hashed Timelock Contract.
The best-known version of the protocol is credited to a developer known as TierNolan, who proposed it in 2013.3
How an atomic swap works, step by step
Alice holds coin X and wants Bob's coin Y. The steps follow the TierNolan protocol.1
Alice picks a secret
Alice creates a random secret and shares only its hash with Bob.4
Alice locks her coins
On chain X she locks coins that Bob can claim by revealing the secret, with a refund to Alice after about 48 hours.1
Bob audits and locks his coins
Bob checks Alice's contract, then locks his coins on chain Y under the same hash, with a shorter refund time of about 24 hours.4
Alice audits and claims
Alice checks Bob's contract and claims his coins, which publishes the secret on chain Y.1
Bob reads the secret and claims
Bob takes the secret from Alice's claim and uses it to claim her coins on chain X.1
Or both refund
If the swap stalls, each side can reclaim its own coins after its timeout expires.4
Worked examples
Example 1 — The trade and its costs
$12 in feesHypothetically Alice swaps 1 BTC for Bob's litecoin at 800 LTC per BTC. Each side needs about two transactions: a lock and a claim.3 Assume a $3 fee per transaction.
| Bob locks | 1 × 800 = 800 LTC |
| Transactions in total | 2 chains × 2 = 4 |
| Total fees | 4 × $3 = $12 |
No exchange holds either coin at any point; the only costs are the network fees.
Example 2 — Why the timeouts differ
24-hour bufferAlice's refund unlocks after 48 hours, Bob's after 24 hours, as in the classic protocol.1
| Alice must claim within | 24 hours |
| Bob's safety margin | 48 − 24 = 24 hours |
If Alice claims late, Bob may already have his refund; if she claims in time, Bob still has a full day to use the secret before Alice's refund opens.4
Example 3 — The free option
$6,400 option valueBob has locked 800 LTC at a hypothetical $80. Before claiming, Alice sees litecoin fall 10%.
| Value when locked | 800 × $80 = $64,000 |
| New LTC price | $80 × 0.90 = $72 |
| Value now | 800 × $72 = $57,600 |
| Drop Alice can avoid | $64,000 − $57,600 = $6,400 |
Alice can simply walk away and wait for her refund, so the party who holds the secret holds an option on the price.1
Atomic swap vs. other ways to change coins
| Aspect | Who holds your coins? | Main risk |
|---|---|---|
| Atomic swap | You, until the swap completes | Missed deadlines, free option, few partners |
| Centralised exchange | The exchange | Exchange failure or freeze. See Counterparty Risk |
| Bridge and wrapped token | The bridge's contracts or signers | Bridge hacks. See Cross-Chain Bridge |
Where atomic swaps are used
Peer-to-peer coin trades
Command-line tools exist for swaps between coins such as Bitcoin, Litecoin and Decred.4 See Decred (DCR).
Moving to and from sidechains
The pegged-sidechains paper expected most transfers to use atomic swaps, avoiding the slow peg.3 See Sidechain.
Lightning payments
The same hashed timelock idea links payments hop by hop on the Lightning Network.2 See Lightning Network.
Decentralised trading
Atomic swaps can underpin exchanges that never take custody. See Centralised and Decentralised Exchanges.
Advantages and disadvantages
Advantages
- No exchange or custodian ever holds your coins.
- All-or-nothing: you get the other coin or your own coin back.
- Uses ordinary transactions, about two on each chain.
- No account, sign-up or withdrawal limit at a third party.
Disadvantages
- Both chains must support hash locks and time locks.
- Coins can stay locked for a day or two if the other side walks away.
- The secret holder gets a free option on the price.
- Finding a partner and agreeing a rate is up to you.
Going deeper
Read as far as you need. Each level builds on the one before it.
A locked box with one key
Beginner
Hash locks and time locks
Intermediate
BIP 199 describes the script: the recipient can spend with the secret plus a signature, or the sender can take the coins back with a signature after a timeout.2
It allows SHA-256 or HASH160 for the hash and either an absolute or a relative time lock.2 Both chains in a swap need to accept the same hash function so one secret unlocks both sides.
Timing and practical risks
Advanced
Each party must claim before its deadline, or the counterparty can take the refund; funds are also tied up for the whole timeout if the other side disappears.1
Before locking, each side should check the other contract's address, amount, time lock and secret hash, and keep its refund transaction safe.4
Decred's reference tools describe themselves as a proof of concept for early adopters, which reflects how hands-on on-chain swaps still are.4
Common mistakes
Skipping the contract audit
Always verify the other side's amount, address, time lock and hash before you lock coins.4
Claiming too late
Miss your deadline and the counterparty may already have taken a refund.1
Ignoring the free option
On a volatile pair, the side holding the secret can abandon the trade if the price moves against them.1
Calling any cross-chain trade atomic
Bridges and exchanges that hold your coins are not atomic swaps. See Cross-Chain Bridge.
Check your understanding
Test yourself before moving on. Each answer comes with an explanation.
Key points to remember
- An atomic swap trades coins across two blockchains without a middleman.
- Hashed timelock contracts make it all-or-nothing.
- Claiming one side reveals the secret that unlocks the other.
- Staggered timeouts protect the party who locks second.
- The secret holder has a free option, and coins can stay locked for hours or days.
Frequently asked questions
Do atomic swaps need an exchange?
Can I atomic-swap any two coins?
What happens if the other person disappears?
Further learning
- Lightning Network
The same building block used for payments.
- Cross-Chain Bridge
The custodial alternative for moving value across chains.
- Centralised and Decentralised Exchanges
Where most cross-coin trading still happens.
Sources
This article is written in our own words. The sources below support the specific facts, rules and figures marked with a number in the text. Links open the original publisher’s page.
- Bitcoin Wiki. Atomic swap (opens in a new tab) Checked .
- Bitcoin Improvement Proposals. BIP 199: Hashed Time-Locked Contract transactions (opens in a new tab) Checked .
- Back, Corallo, Dashjr et al.. Enabling Blockchain Innovations with Pegged Sidechains (2014) (opens in a new tab) Checked .
- Decred (GitHub). atomicswap: on-chain atomic swaps for Decred and other cryptocurrencies (opens in a new tab) Checked .
Educational content, not financial advice. Examples use hypothetical prices and simplified costs; actual fees, margin rules and regulations vary by broker, market and country. We are not affiliated with any publisher linked above. Last reviewed . Report an error or request a source credit.