What is atomic swap?

A direct exchange of coins between two parties on different chains that either completes fully for both or not at all, enforced by cryptography rather than by a custodian.

Not yet verifiedHow we verify

3 min read

In this entry

A direct exchange of coins between two parties on different chains that either completes fully for both or not at all, enforced by cryptography rather than by a custodian.

The classic construction locks each side behind the same secret with a time limit, so revealing the secret to claim one side automatically reveals it for the other. It removes counterparty risk without an intermediary.

Atomic swaps stayed niche because they need both parties online, matching demand, and compatible scripting on both chains. They matter more as an idea than as a product: they demonstrate that cross-chain trade does not logically require a trusted middle, which is the benchmark every bridge is measured against.

How it works

The standard construction is a hash time-locked contract, or htlc, and it runs in four steps.

  1. Alice picks a random secret and computes its hash. She locks her coins on chain A with a script saying: payable to Bob if he presents a value hashing to this, or refundable to Alice after 48 hours.
  2. Bob sees the hash on chain A and locks his coins on chain B with a matching script: payable to Alice if she presents the preimage, refundable to Bob after 24 hours.
  3. Alice claims Bob's coins on chain B by publishing the secret. That claim is a public transaction, so the secret is now visible to everyone.
  4. Bob reads the secret from chain B and uses it to claim Alice's coins on chain A. Both sides have completed.

The timelocks are deliberately unequal. Bob's refund window is shorter than Alice's so that if Alice reveals the secret at the last moment, Bob still has time to use it. If either party walks away before step 3, both refunds fire and nobody loses anything but fees.

Both chains must support hash locks and time locks in script, which is why the technique works between Bitcoin-style chains and Ethereum-style chains but not with every asset.

Example

Illustrative: Alice swaps 0.1 BTC for 1.5 ETH with Bob. She locks 0.1 BTC with a 48-hour refund; Bob locks 1.5 ETH with a 24-hour refund. Alice claims the ETH at hour 20, publishing the secret. Bob reads it and claims the BTC at hour 21. If Alice had done nothing, Bob's ETH would have returned to him at hour 24 and her BTC at hour 48, with each party out only the network fees of the locking transactions.

Why it matters when you buy

For ordinary buying this is background. Its value to you is as a comparison: every bridge and every exchange you use instead of an atomic swap is a party you are trusting with custody for some window. Knowing that a trustless version exists makes the question "what exactly am I trusting here" concrete. See the guide on sending crypto across chains and the comparison of centralized and decentralized exchanges.

  • htlc — the hash and time lock construction used
  • bridge — the custodial alternative most people use
  • p2p trading — trading without an exchange in the middle
  • dex — on-chain trading within a single chain
  • counterparty risk — what the design removes
  • wrapped token — what bridges issue instead

Questions

Why are atomic swaps not the normal way to trade?

They need a counterparty who wants the opposite trade at the same time and stays online through the whole sequence. Order books and pools solve that matching problem, which is why they dominate.

Can I atomically swap any two assets?

No. Both chains need compatible hash and time lock support in their scripting, and both assets need to be native to a chain that has it. Tokens without that support cannot participate directly.

Yes. Lightning routes payments across channels using the same hash and time lock idea, which is why a multi-hop payment either completes end to end or fails entirely. See lightning network.