A cross-chain swap exchanges tokens on one blockchain for tokens on another blockchain in a single atomic operation. The user initiates a trade, the protocol handles bridging, and both parties receive their assets or both transactions revert. Partial fills do not occur.
Why Not Just Bridge and Swap Manually?
A user wanting AVAX on Avalanche but holding USDC on Ethereum must: (1) bridge USDC from Ethereum to Avalanche (lock it, mint wrapped USDC, 10-20 minutes), (2) swap wrapped USDC for AVAX on a Solana DEX (2 minutes), (3) bridge AVAX back to Ethereum if needed (10-20 minutes). Three transactions, three fees, three confirmation delays, and three points of failure (if any bridge fails, the entire trade fails).
A cross-chain swap abstracts these steps. The user calls a single contract function with the input token, output token, input and output chains, and minimum output amount. The protocol handles bridging internally and returns the result to the user's wallet in one transaction (from the user's perspective).
Hash Time-Lock Contracts (HTLCs)
The mechanism behind atomic swaps is the HTLC, a smart contract that locks funds with two conditions: (1) a cryptographic hash, and (2) a time delay.
Party A generates a random secret S (e.g., 32 bytes). Computes hash H = SHA256(S). Creates a smart contract on Chain 1 that says: "Release the locked amount if someone provides S before block height B; otherwise, refund after block B."
Party B, seeing the locked funds and hash H, creates a corresponding contract on Chain 2 with the same hash H. Party B locks their tokens and waits.
Party A reveals S to claim Party B's tokens on Chain 2. When S is revealed, Party B can use the same S to claim Party A's tokens on Chain 1 (because the contracts share the same hash). If Party A never reveals S, Party B's tokens are refunded after the timelock expires. Party A's tokens are still locked but refundable after B block confirmations.
Advantage: neither party can cheat. If one party abandons the trade, the other gets refunded.
Disadvantage: both parties must participate. If no one is willing to take the other side of the trade, the swap does not happen. This is why automated market makers (AMMs) replaced atomic swaps: AMMs always have a counterparty (the liquidity pool) at a known price.
Bridge-Based Cross-Chain Swaps
Modern cross-chain DEXs do not use atomic swaps for retail trades. Instead, they use bridge protocols. The flow:
- User calls swap(inputToken, outputToken, inputChain, outputChain, amount, minOutput) on the DEX contract on inputChain.
- The DEX locks inputToken in a bridge contract on inputChain and sends a message to the bridge validator set.
- Bridge validators on outputChain verify the message (ensuring it came from the input contract) and mint wrapped inputToken on outputChain.
- The DEX swaps wrapped inputToken for outputToken on a DEX on outputChain.
- The wrapped outputToken is burned or swapped for native outputToken, and the user receives the final asset on outputChain.
Time: 5-15 minutes (bridge latency dominates; DEX swaps are < 30 seconds).
Cost: bridge fee (0.1-0.5%), DEX swap fee (0.25-1%), and gas on both chains (USD 5-50 depending on network).
Risk: Bridge Failure
If the bridge loses consensus or is hacked, wrapped tokens become worthless. Example: the Nomad bridge (2022) had a bug where a contract state variable was incorrectly initialized, allowing anyone to mint wrapped tokens without providing collateral. An attacker withdrew USD 190M. Atomic swaps avoid this (no wrapped assets, only native tokens), but manual bridging is slow and operationally burdensome.
Trade-off: bridge-based swaps are faster and easier for users but carry counterparty risk (bridge operator). Atomic swaps are slow but have no counterparty.
When Cross-Chain Swaps Fail
If minOutput is not met due to slippage, the transaction reverts on the destination chain, and the user's funds are locked pending refund. Refunds take as long as the bridge (5-15 minutes typically).
If the bridge becomes unavailable between initiation and completion, the user's tokens remain locked on the source chain until the bridge recovers or the timelock expires.
If the user submits a swap but network fees spike before the bridge processes the message, the transaction may not execute, and the user loses gas fees without swapping. Always include a deadline parameter in cross-chain swaps to cancel if execution is delayed.
Liquidity and Price Discovery
Cross-chain swaps depend on liquidity pools on the destination chain. If you want to swap USDC (Ethereum) for AVAX (Avalanche), there must be a USDC/AVAX liquidity pool on Avalanche. If the pool has low TVL, the swap will have high slippage. Popular pairs (ETH, USDC, BNB) have deep liquidity across chains; niche tokens may not be swappable across certain chain pairs.
Use Cases
Cross-chain swaps are useful for: rebalancing portfolios across chains (without manual bridging), building chain-agnostic dApps (your smart contract calls a cross-chain swap DEX to access liquidity on another chain), and arbitrage (buying on one chain where price is low, selling on another where price is high).
For small trades (< USD 10,000), the bridge and swap fees are often 2-3%, making manual bridging + single-chain swap competitive or cheaper on total fees.
Cross-chains swaps use smart contracts and a technology called Hash Time Lock Contracts (HTLCs) to facilitate token exchanges between two parties on two different blockchains.
Cross-chain bridge are critical for the blockchain ecosystem as they eliminate third-party entities from the token exchange process and facilitate multi-blockchain transactions.

