Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Atomic Swap

A peer-to-peer, trustless method for exchanging cryptocurrencies across different blockchains using hash-locked, time-locked smart contracts.
Chainscore © 2026
definition
BLOCKCHAIN GLOSSARY

What is an Atomic Swap?

A trustless, peer-to-peer method for exchanging cryptocurrencies across different blockchains without intermediaries.

An atomic swap is a smart contract-enabled protocol that allows two parties to directly exchange distinct cryptocurrencies—such as Bitcoin for Litecoin—without relying on a centralized exchange or third-party custodian. The term "atomic" refers to the transaction's fundamental property: it either completes entirely for both parties or fails completely, with funds returned. This is enforced by Hash Time-Locked Contracts (HTLCs), which use cryptographic hash functions and time constraints to ensure that either both legs of the trade execute or neither does, eliminating counterparty risk.

The core mechanism relies on two key components: a hashlock and a timelock. First, Party A creates an HTLC on Chain A, locking funds with a cryptographic puzzle (the hashlock). To claim these funds, Party B must present the secret solution (the preimage) to this puzzle within a set timeframe. Party B then creates a corresponding HTLC on Chain B, using the same hashlock. When Party A reveals the preimage to claim the funds on Chain B, they inadvertently disclose it, allowing Party B to finally claim the original funds on Chain A. If any step fails, the timelocks expire, and all funds are refunded.

Atomic swaps enable true cross-chain interoperability, facilitating decentralized exchange (DEX) functionality between otherwise isolated blockchain networks. Major use cases include decentralized trading, portfolio rebalancing across chains, and enhancing liquidity in decentralized finance (DeFi) without wrapping assets. They are foundational to cross-chain decentralized exchanges and certain blockchain bridges. However, challenges remain, including technical complexity, limited liquidity for specific trading pairs, and the requirement that both blockchains support the necessary scripting capabilities for HTLCs or similar smart contract logic.

The first successful atomic swap was executed between Bitcoin and Litecoin in September 2017, demonstrating the practical viability of the concept pioneered by Tier Nolan. Today, implementations exist on networks like Ethereum, Bitcoin (via scripts), Litecoin, and various Cosmos-SDK chains. While similar in goal to cross-chain bridges, atomic swaps are typically peer-to-peer asset exchanges, whereas bridges often involve minting wrapped representations of an asset on a destination chain, which introduces different trust assumptions and centralization risks.

etymology
TERM HISTORY

Etymology & Origin

The term 'Atomic Swap' reveals its core technical principle through its linguistic roots, combining a concept from computer science with a fundamental operation in decentralized finance.

The word atomic is borrowed from computer science, where an atomic operation is one that executes completely or not at all, with no intermediate state. In the context of a swap, this guarantees that either both parties receive the other's assets simultaneously, or the entire transaction is canceled, eliminating counterparty risk. The term swap is a standard financial term for the exchange of one asset for another. Together, they precisely describe a trustless cross-chain exchange.

The conceptual origin of atomic swaps is tied to the development of Hashed Timelock Contracts (HTLCs), the cryptographic primitive that makes them possible. While the idea of cross-chain trading was discussed in early Bitcoin forums, the first practical implementation is widely credited to Tier Nolan, who outlined the complete protocol in 2013. This protocol leveraged Bitcoin's scripting capabilities to create the conditional locks necessary for the atomic property.

The evolution of the term mirrors technological adoption. Initially a niche concept for peer-to-peer trading between Bitcoin-like chains, 'atomic swap' has expanded to include swaps between diverse ecosystems (e.g., Bitcoin to Ethereum) via intermediary wrapping of assets. The core etymology remains apt, as the guarantee of atomicity—all-or-nothing settlement—is the defining and non-negotiable feature of the mechanism, distinguishing it from custodial or sequential exchange methods.

how-it-works
CROSS-CHAIN MECHANISM

How an Atomic Swap Works

An atomic swap is a peer-to-peer mechanism for exchanging cryptocurrencies across different blockchains without a trusted third party, using cryptographic proofs to ensure the trade either completes fully or fails entirely.

An atomic swap is a trustless exchange of cryptocurrencies between two parties on distinct blockchains, such as Bitcoin and Ethereum. The process is secured by Hash Time-Locked Contracts (HTLCs), which are smart contracts or script-based agreements that enforce the swap's conditions. The core principle is atomicity: the entire transaction sequence is a single, indivisible operation. Either both parties successfully claim the funds, or the contracts expire and all funds are returned to their original owners, eliminating counterparty risk.

The technical execution involves a multi-step cryptographic handshake. First, Party A initiates the swap by locking funds into an HTLC on Chain A, using a cryptographic hash of a secret preimage. Party B, seeing this commitment, can then lock their funds into a corresponding HTLC on Chain B, using the same hash. To claim Party A's funds, Party B must reveal the secret preimage, which simultaneously unlocks their own funds for Party A. This hashlock ensures the secret is the key to both contracts, while the timelock guarantees funds are not locked indefinitely if one party abandons the process.

Atomic swaps enable cross-chain interoperability for assets like BTC, LTC, and various ERC-20 tokens, operating either on-chain directly on the respective blockchains or off-chain via second-layer networks like the Lightning Network for near-instant, low-cost trades. This mechanism underpins decentralized exchanges (DEXs) by allowing direct wallet-to-wallet trades, reducing reliance on centralized custodians and mitigating risks associated with exchange hacks or insolvency. The process is transparent and verifiable by anyone on the involved blockchains.

While powerful, atomic swaps have practical limitations. They require compatible cryptographic hash functions (typically SHA-256) and scripting capabilities like those in Bitcoin Script or Ethereum smart contracts. They also necessitate both parties to be online during the swap initiation and claim periods. Furthermore, the inherent finality times and transaction fees of the underlying blockchains can affect speed and cost, making them less suitable for micro-transactions compared to dedicated layer-2 solutions.

key-features
MECHANICAL PROPERTIES

Key Features of Atomic Swaps

Atomic swaps are defined by a set of core cryptographic and economic properties that enable trustless cross-chain exchange.

01

Trustless Execution

Atomic swaps eliminate the need for a trusted third party or centralized exchange. The swap protocol itself, enforced by cryptographic hash functions and Hash Time-Locked Contracts (HTLCs), guarantees that either the entire trade completes successfully or all funds are returned to their original owners. This removes counterparty risk and custodial risk.

02

Cross-Chain Interoperability

The primary function is to facilitate direct asset exchange between different blockchain networks. For example, a user can swap Bitcoin (BTC) on its native chain for Ethereum (ETH) on its native chain without wrapping assets. This is achieved through compatible cryptographic primitives (like SHA-256) and script support (e.g., for HTLCs) on both chains.

03

Atomicity Guarantee

The swap is atomic, meaning it is indivisible. The transaction state has only two possible outcomes:

  • Success: Both parties fulfill the contract terms and receive the other's assets.
  • Failure: The swap expires, and all locked funds are refunded. There is no intermediate state where one party receives an asset without the other also receiving theirs, preventing theft.
04

Hash Time-Locked Contracts (HTLCs)

This is the core technical mechanism. An HTLC is a conditional payment that requires the recipient to provide a cryptographic proof (preimage) of a known hash within a specified time frame.

  • Hashlock: The secret preimage must be revealed to claim funds.
  • Timelock: A refund path activates after a set block height or timestamp, protecting the initiator.
05

Decentralization & Censorship Resistance

Because atomic swaps are peer-to-peer and executed directly on-chain, they inherit the decentralization properties of the underlying blockchains. There is no central entity that can block, reverse, or censor a swap. Settlement is permissionless and relies solely on the consensus rules of the involved networks.

06

Challenges & Limitations

Practical implementation faces hurdles:

  • Technical Complexity: Requires compatible scripting (e.g., not all chains support HTLCs natively).
  • Liquidity Discovery: Finding a counterparty is difficult without a coordinating layer or order book.
  • Timing & Fees: Participants must be online, and on-chain execution incurs transaction fees on both chains, which can be high.
visual-explainer
TRUSTLESS EXCHANGE

Visual Explainer: The Atomic Swap Flow

This visual guide breaks down the step-by-step process of an atomic swap, a peer-to-peer mechanism for exchanging cryptocurrencies across different blockchains without a trusted intermediary.

An atomic swap is a smart contract-enabled protocol that allows two parties to exchange distinct cryptocurrencies directly, ensuring the trade either completes entirely for both parties or fails for both, preventing one side from stealing funds. This atomicity—the "all-or-nothing" property—is enforced by cryptographic hash functions and time-locked contracts. The process typically relies on the Hashed Timelock Contract (HTLC), which uses a secret key and a deadline to secure the conditional transfer of assets on both involved blockchains.

The core flow begins when Party A, wanting to trade Bitcoin for Party B's Ethereum, creates an HTLC on the Bitcoin blockchain. This contract locks the BTC with a cryptographic puzzle: to claim it, Party B must present the correct preimage (a secret number) that produces a specific hash. Party A then shares only this hash with Party B. In response, Party B creates a corresponding HTLC on the Ethereum blockchain, locking the ETH with the same hash condition. This creates the interdependent link between the two transactions.

To finalize the swap, Party A claims the ETH by revealing the preimage to unlock the Ethereum contract. This action, which is public on the Ethereum blockchain, inadvertently reveals the secret to Party B. Party B can then use the now-public preimage to unlock and claim the BTC from the original Bitcoin HTLC. If either party fails to act within the predefined timelock periods, the contracts automatically refund the locked funds to their original owners, making the process secure and trust-minimized.

This mechanism enables cross-chain interoperability for assets like BTC and ETH without centralized exchanges or wrapped token bridges. Key technical prerequisites include compatible cryptographic hash functions (like SHA-256) on both chains and support for a degree of programmability, such as Bitcoin's Script or Ethereum's smart contracts. The process demonstrates a foundational use case for cryptographic commitments and time-based contingencies in decentralized finance.

examples
ATOMIC SWAP

Examples & Implementations

Atomic swaps are implemented through specific protocols and smart contracts, enabling direct cross-chain asset exchange. Key implementations include hash timelock contracts (HTLCs), decentralized exchange (DEX) integrations, and specialized bridging protocols.

01

Hash Timelock Contract (HTLC)

The foundational smart contract mechanism enabling atomic swaps. It uses a cryptographic hash and a timelock to enforce the atomicity of the exchange.

  • Process: Party A locks funds with a hash preimage. Party B, upon seeing the lock, creates a corresponding lock on the other chain using the same hash. Party A reveals the preimage to claim Party B's funds, which then allows Party B to claim the original funds.
  • Key Property: The swap either completes entirely for both parties or funds are refunded after the timelock expires, eliminating counterparty risk.
02

Cross-Chain DEX Integration

Decentralized exchanges implement atomic swap protocols to facilitate trading between native assets of different blockchains without wrapped tokens.

  • Example: THORChain uses a continuous liquidity pool model and a network of nodes to perform cross-chain swaps (e.g., Bitcoin for Ethereum).
  • Mechanism: Users deposit into a vault on one chain, the network coordinates the swap via its BFT consensus, and assets are released from a vault on the destination chain. This creates a non-custodial, trust-minimized bridge.
03

Lightning Network & Layer-2 Swaps

Atomic swaps are used to exchange assets between different Layer-2 payment channels or between a Layer-1 and a Layer-2 network.

  • Submarine Swaps: Allow a user to move Bitcoin from the Lightning Network (Layer-2) to the Bitcoin base chain (Layer-1) by routing through an on-chain HTLC. The same concept applies for swapping between Lightning and Litecoin networks.
  • Use Case: Enables liquidity movement across scaling solutions without centralized intermediaries, crucial for multi-chain microtransaction ecosystems.
04

Inter-Blockchain Communication (IBC) Transfers

Within the Cosmos ecosystem, the Inter-Blockchain Communication protocol facilitates atomic cross-chain transfers, a form of atomic swap for native tokens.

  • Process: IBC packets contain tokens and are relayed between chains. A proof of lock on the source chain and a proof of unlock on the destination chain are verified. The transaction is atomic; if the proof verification on the destination fails, the tokens remain locked and can be returned.
  • Distinction: While often for transfers, IBC can be used as a primitive for more complex cross-chain swaps between IBC-enabled chains like Osmosis and Cosmos Hub.
05

Atomic Swap Protocols & Tooling

Several dedicated protocols and libraries provide the infrastructure to execute peer-to-peer atomic swaps.

  • Komodo: Pioneered the BarterDEX protocol, using atomic swaps for decentralized trading across many blockchains.
  • Liquality: Provides an open-source wallet and SDK for performing atomic swaps between Bitcoin, Ethereum, and other chains.
  • Boltz: A non-custodial exchange offering atomic swaps for Lightning Network and liquid assets, using Submarine Swaps and Reverse Submarine Swaps.
06

Limitations & Practical Considerations

While theoretically elegant, atomic swaps face practical constraints that affect their widespread adoption.

  • Blockchain Compatibility: Requires compatible hash functions (e.g., SHA-256) and timelock functionality on both chains.
  • Liquidity & Discovery: Finding a counterparty with the exact desired asset pair and amount can be difficult without order books or liquidity pools.
  • User Experience: The process involves multiple steps (generating secrets, broadcasting transactions) and can be slower than centralized exchanges due to block confirmations and timelocks.
security-considerations
ATOMIC SWAP

Security Considerations & Limitations

While atomic swaps enable trustless cross-chain trading, their security is contingent on the underlying blockchain protocols and the correct implementation of the swap contract.

01

Time-Lock Vulnerabilities

Atomic swaps rely on Hash Time-Locked Contracts (HTLCs). If the time-lock duration is set incorrectly, it can create vulnerabilities:

  • Expired Locks: If the counterparty's lock expires before you claim, your funds are returned, but the swap fails.
  • Race Conditions: A malicious participant could attempt to front-run the final claim transaction.
  • Network Congestion: High fees or slow confirmations on one chain could prevent timely claim execution, causing a refund.
02

Protocol & Implementation Risks

The security of an atomic swap is only as strong as the weakest link in its technical stack.

  • Smart Contract Bugs: Flaws in the HTLC script or the underlying wallet software can lead to fund loss.
  • Chain Reorganizations: A reorg on either blockchain after a transaction is broadcast but before confirmation can invalidate the swap, potentially enabling double-spend attacks.
  • Incompatible Upgrades: Hard forks or consensus changes on one chain can break the cryptographic assumptions (e.g., signature schemes) required for the swap.
03

Liquidity & Counterparty Limitations

Atomic swaps are peer-to-peer, which introduces practical constraints.

  • Limited Discovery: Finding a counterparty with the exact asset pair and amount you desire can be difficult without a centralized order book.
  • Price Discovery: The lack of a centralized market maker can lead to poor exchange rates compared to liquid order books on centralized exchanges (CEXs).
  • Partial Fill Risk: Atomic swaps are all-or-nothing; you cannot partially fill a large order, limiting utility for large trades.
04

Privacy & Front-Running Exposure

The on-chain nature of most atomic swaps exposes participants to surveillance and predatory trading.

  • Transaction Visibility: The hash pre-image and contract addresses are public, allowing network observers to link the participating wallets and amounts.
  • Mempool Sniping: An adversary monitoring the mempool could see the claim transaction, learn the secret pre-image, and attempt to broadcast a competing claim transaction with a higher fee to steal the funds.
05

Cross-Chain Bridge Dependency

Swaps between non-interoperable chains (e.g., Bitcoin to Ethereum) often require wrapped assets, introducing bridge risk.

  • Custodial Risk: Using a wrapped BTC (WBTC) bridge to facilitate an Ethereum-based swap means trusting the bridge's custodians or multisig signers.
  • Bridge Exploits: The swap's security is now contingent on the bridge's smart contract security, which has been a major attack vector (e.g., Wormhole, Ronin). This negates the pure trustless model of a native atomic swap.
EXCHANGE COMPARISON

Atomic Swaps vs. Centralized & Other Decentralized Exchanges

A feature and risk comparison of peer-to-peer atomic swaps against traditional exchange models.

Feature / MetricAtomic Swap (P2P)Centralized Exchange (CEX)Automated Market Maker (AMM DEX)

Custody of Funds

Non-custodial

Custodial

Non-custodial

Counterparty Risk

Eliminated via HTLCs

High (Exchange is counterparty)

Low (Protocol is counterparty)

Requires Registration/KYC

Typical Fee Structure

Network gas fees only

Taker/maker fees + withdrawal fees

Swap fee (e.g., 0.3%) + network gas

Liquidity Source

Counterparty order book

Centralized order book

Liquidity pools

Cross-Chain Capability

Settlement Finality

Atomic (instant & guaranteed)

Delayed (after order matching)

Atomic (within the same chain)

Operational Central Point of Failure

ATOMIC SWAP

Frequently Asked Questions (FAQ)

Atomic swaps enable the direct, trustless exchange of cryptocurrencies across different blockchains. This FAQ addresses the core technical concepts, mechanics, and practical considerations.

An atomic swap is a peer-to-peer, trustless mechanism for exchanging one cryptocurrency for another directly between users on different blockchains without requiring a centralized intermediary like an exchange. The swap is 'atomic' because it follows the principle of atomicity from database systems: the entire transaction either completes successfully for both parties or fails completely, eliminating counterparty risk. This is achieved using Hash Time-Locked Contracts (HTLCs), which use cryptographic hashes and time constraints to ensure that either both parties fulfill the agreement or the funds are returned to their original owners.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team