Cipherbase
BTC ETH XMR
Cryptocurrency Entry 23 of 25

Atomic Swaps: How Trustless Cross-Chain Crypto Trading Works

Atomic swaps let two parties exchange cryptocurrencies across different blockchains with no middleman and no counterparty risk. The trade either completes in full or not at all, eliminating the need for a centralized exchange. They are a foundational primitive in decentralized finance and peer-to-peer trading.

Animated diagram of a transaction signed by one of several possible senders, hiding which one is real.
Animated diagram of a transaction signed by one of several possible senders, hiding which one is real.
On this page
  1. How Atomic Swaps Work
  2. Technical Requirements
  3. On-Chain vs. Off-Chain (Lightning) Atomic Swaps
  4. Real-World Applications
  5. Limitations and Practical Challenges
  6. Security Considerations
  7. Summary and Key Takeaways

Atomic swaps let two people exchange cryptocurrencies across different blockchains without touching a centralized exchange. No middleman, no custodian, no trust required. The "atomic" part means the trade either completes fully or it doesn't happen at all — you can't end up in a situation where one person sends funds and the other walks away.

“In the future, I think there will be more countries that use crypto.”

— Vitalik Buterin

That guarantee sits at the heart of decentralized finance, and it's increasingly relevant if you're interested in P2P trading, privacy-focused transactions, or keeping your assets in wallets you actually control.

How Atomic Swaps Work

The whole thing runs on a cryptographic construct called a Hash Time-Locked Contract (HTLC). An HTLC enforces two conditions at once.

The first is a hashlock: funds can only be claimed by someone who knows a secret value that produces a specific hash. The second is a timelock: if the trade doesn't complete within a set window, both parties get their funds back automatically.

The Step-by-Step Process

Say Alice holds Bitcoin and Bob holds Litecoin. Here's how they pull off a swap:

  1. Alice generates a secret — a random value S — and computes its hash H = hash(S).
  2. Alice creates an HTLC on Bitcoin, locking her BTC with one condition: anyone who reveals the preimage of H within 24 hours can claim the funds.
  3. Bob sees the contract on-chain and creates a matching HTLC on Litecoin, locking his LTC with the same hash H but a shorter timelock — say, 12 hours.
  4. Alice claims Bob's LTC by revealing the secret S on the Litecoin chain.
  5. Bob reads S from the Litecoin blockchain (it's now public) and uses it to claim Alice's BTC.

If either party bails at any point, the timelocks expire and everyone gets their original funds back. The asymmetric windows — 24 hours versus 12 — make sure Bob always has enough time to respond after Alice reveals her secret.

Technical Requirements

Not every blockchain can participate in an atomic swap. Both chains need to support a few specific things.

They need scripting capability — specifically OP_CHECKLOCKTIMEVERIFY (CLTV) for Bitcoin-based chains, or equivalent smart contract logic on EVM chains. They need to share the same hashing algorithm, typically SHA-256. And for Bitcoin-family chains, Segregated Witness (SegWit) is required because it fixes transaction malleability, which would otherwise break the HTLC entirely.

A minimal HTLC redeem script in Bitcoin Script looks like this:

OP_IF
    OP_SHA256 <hash> OP_EQUALVERIFY
    OP_DUP OP_HASH160 <Bob's pubkey hash> OP_EQUALVERIFY OP_CHECKSIG
OP_ELSE
    <locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP
    OP_DUP OP_HASH160 <Alice's pubkey hash> OP_EQUALVERIFY OP_CHECKSIG
OP_END

On Ethereum, you'd express the same logic in Solidity, which is how Bitcoin-to-Ethereum swaps become possible — compatible HTLC implementations on both sides, speaking the same cryptographic language.

If you're working from the command line, a typical swap flow looks something like this:

# Initiate a swap (Alice's side)
atomicswap --chain=bitcoin initiate <bob_btc_address> 0.1

# Participate in a swap (Bob's side)
atomicswap --chain=litecoin participate <alice_ltc_address> 5.0 <secret_hash>

# Redeem funds after the other party participates
atomicswap --chain=litecoin redeem <contract_tx> <contract> <secret>

On-Chain vs. Off-Chain (Lightning) Atomic Swaps

FeatureOn-Chain Atomic SwapOff-Chain (Lightning) Atomic Swap
SpeedMinutes to hoursNear-instant (sub-second)
FeesHigher (miner fees for each HTLC)Very low (Lightning routing fees)
Chain requirementsBasic script supportBoth chains need Lightning support
Amount flexibilityAny amountLimited by channel liquidity
PrivacyModerateImproved via onion routing
ComplexityLowerHigher (channel management needed)
Best use caseLarge, infrequent tradesSmall, frequent trades

Lightning Network atomic swaps — sometimes called submarine swaps — run on the same HTLC mechanism but route payments through off-chain payment channels. That's what makes services like Boltz Exchange capable of converting between Bitcoin and Lightning Bitcoin almost instantly, with fees that barely register.

Real-World Applications

Decentralized Exchanges (DEXes)

Several production DEXes run on atomic swap technology. Komodo's AtomicDEX supports swaps across 99+ blockchains. THORChain uses a variation of the idea to enable native cross-chain liquidity without wrapped tokens. These platforms matter for P2P trading because they eliminate custodial risk entirely — the exchange never touches your funds.

Privacy-Preserving Trades

Atomic swaps are one of the few mechanisms that don't require KYC by design. Two parties swap directly — no exchange account, no identity check, no third-party holding your coins in between. The only on-chain footprint is the HTLC transactions themselves.

Pair that with a privacy coin like Monero, and you get trades that are structurally resistant to surveillance. Worth noting: Monero-Bitcoin atomic swaps require a specialized HTLC variant because of Monero's non-standard scripting, so it's more complex than a standard Bitcoin-Litecoin swap.

Portfolio Rebalancing Without Custodial Risk

Sophisticated traders use atomic swaps to rebalance across chains without routing through a centralized exchange. Your assets stay in self-custody throughout the entire trade. For anyone thinking about cryptocurrency inheritance planning, this matters — assets that never leave your own wallets are far simpler to hand off to an inheritor than funds sitting on an exchange.

Limitations and Practical Challenges

Atomic swaps are powerful, but they come with real tradeoffs you should understand before depending on them.

Liquidity is the biggest constraint. Finding a counterparty willing to swap the exact pair you want, in the right amount, at an acceptable rate — without a centralized order book — is genuinely hard. Most atomic swap tools either plug into a matching service or expect you to negotiate off-chain before anything happens on-chain.

Chain compatibility shrinks your options considerably. Not every blockchain supports the scripting required. ERC-20 tokens swap with each other easily through smart contracts, but connecting to Bitcoin takes more careful HTLC coordination on both sides.

User experience is still rough in most implementations. Generating HTLCs, watching timelocks, manually redeeming contracts — it's error-prone without solid tooling. Mainstream adoption is still held back by how much complexity leaks through to the user.

Timing attacks are a known theoretical risk. The initiating party learns something about the other party's intentions and could time out strategically. Properly designed timelocks reduce the practical risk, but it's worth being aware of.

Security Considerations

The cryptographic foundation is solid, but the implementation details are where things can go wrong.

The secret S must come from a cryptographically secure random source. A weak secret breaks the entire security model from the start. Timelocks need to be calibrated relative to expected block confirmation times — set them too short, and network congestion could cause a legitimate redemption to fail, triggering a refund to the wrong party. A secret used in one swap should never be reused, because reuse lets observers correlate transactions across multiple swaps. On EVM chains, HTLC contracts should be audited; a bug in the refund logic can lock funds permanently.

One thing worth flagging for anyone doing cryptocurrency inheritance planning: if a swap is initiated but the inheritor doesn't know to complete it before the timelock expires, the funds get reclaimed by the original counterparty. Understanding how timelock expiry works isn't optional in that context.

Summary and Key Takeaways

Atomic swaps are a mature cryptographic protocol for trustless, cross-chain trading without intermediaries. They work through Hash Time-Locked Contracts that guarantee either both sides of a trade complete or neither does. The technology is real and production-ready in several DEXes, but practical limitations around liquidity, chain compatibility, and tooling mean it works best for users who understand what's happening under the hood. If you value self-custody and want to trade across chains without handing your funds to an exchange, atomic swaps are one of the most technically sound ways to do it.

Frequently Asked Questions

What is an atomic swap?

An atomic swap is a way to exchange one cryptocurrency for another directly between two people, without using a centralized exchange like Coinbase or Binance. The trade either completes fully for both sides or doesn't happen at all, so neither person can cheat the other or walk away with both coins.

Do I need to trust the person I'm trading with in an atomic swap?

No, that's the key advantage — atomic swaps are trustless, meaning the technology enforces the trade using smart contracts called Hash Time-Locked Contracts (HTLCs). If one party doesn't fulfill their side within a set time window, the funds are automatically returned to their original owners.

What cryptocurrencies can be used in atomic swaps?

Atomic swaps work between cryptocurrencies that share compatible blockchain technology, specifically those that support the same hashing algorithm and HTLCs — Bitcoin and Litecoin are a classic example. Not all crypto pairs are compatible, so it's worth checking whether the two coins you want to swap meet the technical requirements before attempting one.

Video Resources

Sources & Further Reading

  • Uniswap Docs — Protocol documentation for the leading automated market maker.
  • Finematics — Educational explainers on DeFi mechanisms with diagrams.
  • Bitcoin Whitepaper — Satoshi Nakamoto's original nine-page design of Bitcoin.
  • Bitcoin.org — Community-maintained introduction, wallet guidance and developer docs.
  • Ethereum.org — Official Ethereum documentation and learning hub.
  • CoinGecko — Market data, exchange listings and asset profiles.
  • Messari Research — Research reports and asset fundamentals.