Atomic Swap

An atomic swap is a peer-to-peer trade of cryptocurrencies on two different blockchains, enforced by smart contracts so that either both sides of the trade complete or neither does, with no exchange or middleman holding the funds.

Most atomic swaps use hash time-locked contracts (HTLCs). One party creates a secret and shares only its hash. Each side then locks their coins in a contract on their own chain. The contract releases the coins to the other party if the matching secret is revealed, or refunds the owner once a deadline passes. Claiming funds on one chain publicly reveals the secret, which lets the other party claim their side on the other chain.

For example, Alice wants to trade bitcoin for Bob's litecoin. Alice locks her BTC under the hash of her secret with a longer deadline. Bob sees this and locks his LTC under the same hash with a shorter deadline. Alice claims the LTC, which exposes the secret. Bob then uses that secret to claim the BTC. If either side stops partway, the timelocks return the coins to their original owners.

Neither party hands coins to a custodian, so atomic swaps avoid exchange counterparty risk. Unlike many cross-chain bridges, they also do not create wrapped tokens. The trade-offs are practical. Both blockchains must support the same hash function and timelocks, and both parties usually need to stay online until the swap finishes. A participant who misses their claim deadline can lose their side of the trade. The party holding the secret can also walk away if prices move, leaving the other waiting for a refund. "Atomic" guarantees all-or-nothing settlement, not a fair price.

Learn more

Related terms