What Is an Atomic Swap? Cross-Chain Crypto Trading Explained
An atomic swap is a trustless, peer-to-peer trade that exchanges cryptocurrencies across two different blockchains without a centralized exchange or custodian. It relies on Hashed Time-Locked Contracts (HTLCs), which combine a hashlock and a timelock so the swap is atomic: either both parties receive their agreed assets, or every coin is automatically refunded to its original owner. Because revealing the secret needed to claim one coin also unlocks the other, neither side can cheat. Both chains must share a compatible hash function. Atomic swaps pioneered trustless interoperability and underpin Lightning Network channels, many DEXs, and modern cross-chain bridges.
An atomic swap is a peer-to-peer trade that exchanges two cryptocurrencies sitting on different blockchains, with no centralized exchange or custodian in the middle. The word "atomic" means the trade is indivisible: either both legs settle and each party receives the asset they agreed on, or nothing happens and every coin returns to its original owner. There is no halfway state where one side is paid and the other is left empty-handed. This is achieved cryptographically through smart contracts called Hashed Time-Locked Contracts (HTLCs), making the swap trustless by design.
How an Atomic Swap Works
The core machinery is the Hashed Time-Locked Contract (HTLC), a small conditional contract deployed on each chain. It combines two locks:
- A hashlock that releases funds only when a secret value (a preimage) matching a published hash is revealed.
- A timelock that refunds the sender automatically if the swap is not completed before a deadline.
Because revealing the secret to claim coins on one chain simultaneously exposes that same secret on the other chain, both parties can complete the trade — or neither can. The shared secret is what binds the two independent blockchains into a single, all-or-nothing transaction.
Step-by-Step: Swapping BTC for ETH
Suppose Alice wants to trade Bitcoin for Bob's Ethereum:
- Alice generates a secret and computes its cryptographic hash. She locks her BTC in an HTLC on the Bitcoin chain, claimable by Bob only if he reveals the matching secret, with a 48-hour refund timer.
- Bob sees the hash (not the secret) and locks his ETH in an HTLC on Ethereum, claimable by Alice with the same hash, but with a shorter 24-hour timer.
- Alice claims the ETH by revealing her secret on Ethereum. This action publishes the secret on-chain.
- Bob reads the now-public secret and uses it to claim the BTC on Bitcoin before his timer expires.
- If anyone walks away, the timelocks refund both parties — no coins are lost.
The asymmetric timers matter: the party who moves first (Alice) gets the longer window, so the counterparty cannot stall and trap funds.
A Worked Numeric Example
Imagine the market rate is 1 BTC = 15 ETH. Alice and Bob agree to swap 0.5 BTC for 7.5 ETH directly, with no exchange fees beyond on-chain network costs.
| Item | Centralized exchange route | Atomic swap route |
|---|---|---|
| Trading fee (0.1%) | ~0.0075 BTC equivalent | 0 |
| Deposit/withdrawal fees | 2 network fees + spread | 0 (direct) |
| Network fees (2 chains) | Often hidden in spread | ~2 on-chain tx fees |
| Custody risk | Funds held by exchange | Self-custody throughout |
| Counterparty risk | Exchange solvency | None (HTLC-enforced) |
In this example Alice keeps custody of her 0.5 BTC until the exact moment Bob's 7.5 ETH becomes claimable, eliminating the window where an exchange holds both deposits. The trade-off is that she pays two on-chain fees and must coordinate timing, which is why atomic swaps suit larger or trust-minimized trades rather than tiny everyday transactions.
Where Atomic Swaps Stand Today
The concept dates back to early Bitcoin-era proposals around 2013, and the first headline on-chain swaps (such as Litecoin–Bitcoin) proved the mechanism works in production. Two technical conditions remain essential:
- Compatible hash functions. Both chains must support the same hashing primitive (for example SHA-256) so the HTLCs on each side can recognize the same secret.
- Scripting capable of timelocks. Each chain needs script support for hashlocks and timelocks, which many Bitcoin-forked codebases inherit natively.
Today, atomic-swap logic lives on inside broader infrastructure: Lightning Network payment channels, the HTLC patterns used by decentralized exchanges, and modern cross-chain bridges. Most users now experience trustless cross-chain trading through a DEX aggregator or bridge interface rather than crafting raw HTLC transactions by hand. Assets like wrapped Bitcoin emerged partly to bring BTC liquidity onto smart-contract chains where atomic swap UX was historically poor.
Risks and Pitfalls
Atomic swaps remove custodial risk, but they are not risk-free:
- Timing and griefing risk. A counterparty can lock funds and then refuse to reveal the secret, forcing you to wait for the timelock refund. Your capital is temporarily frozen even though you eventually get it back.
- Chain compatibility limits. Both chains must share a compatible hash function and scripting model; many incompatible chains cannot swap natively without a bridge.
- Network fee exposure. You pay fees on both chains regardless of outcome, so failed or abandoned swaps still cost gas.
- Complexity and UX. Hand-rolled atomic swaps require careful timer configuration; a misconfigured timelock can let a counterparty claim both legs.
- Liquidity fragmentation. Finding a direct counterparty for an exact pair and amount is harder than tapping a deep exchange order book.
COINOTAG Perspective
Atomic swaps were the original blueprint for trustless interoperability, and their DNA now runs through almost every serious cross-chain product. For COINOTAG readers, the practical takeaway is this: you rarely need to build an HTLC yourself, but understanding the mechanism helps you judge which bridges and DEXs are genuinely trust-minimized versus those that reintroduce a custodian. When a platform claims to be "decentralized" yet holds both sides of your trade, it is not delivering the atomic-swap guarantee. The all-or-nothing settlement model remains the gold standard against which cross-chain safety should be measured.
To go deeper, compare how custodial venues differ from self-custody trading in our guide on centralized vs decentralized exchanges, and review how multi-chain transfers add up in the complete guide to crypto network fees.