Simple Base SwapSimple Base SwapOpen app
← All articles
Sep 12, 2026·5 min read

Atomic swaps and HTLCs, explained: the older idea behind trustless trading

baseguidesdefi
base

Every time you swap a token on Base, a smart contract makes sure the trade is all or nothing. Either both sides of the exchange happen, or none of it does. That guarantee feels obvious now, but it did not always exist between two separate blockchains. Atomic swaps were an early answer to a hard question: how do two people trade assets on different chains without trusting each other or a middleman? The idea is not something you will use directly on Base, but understanding it makes it much easier to see why modern swaps and bridges are built the way they are.

The problem atomic swaps were built to solve

Imagine Alice holds a coin on one blockchain and Bob holds a coin on a completely separate blockchain, and they want to trade. Neither chain knows anything about the other. There is no shared ledger to check, and no built in way for one chain to confirm what happened on the other.

The obvious solution is to find someone both parties trust to hold both assets and release them once the trade is confirmed. But that reintroduces exactly the problem self custody tries to avoid: a third party that could disappear with the funds, freeze them, or simply make a mistake. Atomic swaps were designed to remove that middleman entirely, using math instead of trust.

How a hash time locked contract works

The mechanism behind an atomic swap is called a hash time locked contract, usually shortened to HTLC. It combines two simple ideas.

The first is a hashlock. Alice picks a secret number, then runs it through a one way hashing function to produce a hash. A one way function is easy to compute in one direction and effectively impossible to reverse, so anyone can verify a guess against the hash, but nobody can work backward from the hash to find the secret.

The second is a timelock. Every step in the swap has a deadline. If the deadline passes without the next step happening, the locked funds are automatically returned to whoever put them in.

Put together, a swap unfolds roughly like this. Alice locks her coin in a contract on her chain, set to release to Bob only if he provides the secret that matches her hash, before a deadline. Bob then locks his coin in a matching contract on his own chain, set to release to Alice under the same hash, with a shorter deadline. Alice claims Bob's coin by revealing her secret on his chain. That action is public, so Bob can now see the secret and use it to claim Alice's coin on her chain before her deadline passes. If Alice never reveals the secret, both timelocks eventually expire and each side gets their original coin back. Either the trade completes for both people, or it fails for both people. There is no outcome where one side loses their asset while the other keeps both.

Why this mattered before smart contract chains talked to each other

HTLCs became well known through the Lightning Network, Bitcoin's payment channel system, and through early cross chain trading between Bitcoin and other blockchains that could not otherwise interact. At the time, there was no practical way to move an asset from one chain to another, so a trustless swap between two separate chains, each just enforcing its own half of the deal, was a genuinely clever workaround.

Why swapping on Base does not use this

A swap on Base, like the ones Simple Base Swap helps you make, does not need any of this machinery, and it is worth understanding why.

An HTLC coordinates two separate actions on two separate blockchains that cannot see each other directly. A swap on Base is a single transaction on a single chain. When you swap one token for another through a liquidity pool, the smart contract checks your balance, moves both tokens, and updates the pool, all inside one atomic transaction that either fully succeeds or fully reverts. There is no waiting for a counterparty to respond, no timelock window, and no risk of the trade half completing, because the entire exchange is enforced by Base's own consensus in one step. Our guide to how a token swap works under the hood covers this mechanism in more detail.

Cross chain movement on Base, such as bringing an asset over from Ethereum, is handled by bridges and messaging systems rather than HTLCs. Those systems solve a similar underlying problem, keeping two chains in sync without a single point of failure, but they use different designs built for speed and for the specific chains involved. Our guides to bridging to Base, bridge aggregators, and cross chain messaging protocols walk through how those systems actually work today.

The tradeoffs that made HTLCs fade from everyday use

Atomic swaps are elegant, but they come with real friction. Both parties generally need to be online and responsive within specific time windows, since a slow counterparty can leave funds locked until a timeout passes. Finding someone to trade with directly, at the size and price you want, is its own challenge without an order book or a liquidity pool. And a participant who locks funds first is briefly exposed to a counterparty who simply never continues the trade, tying up their assets until the timelock expires and they can reclaim them.

Automated market makers and liquidity pools, the model behind most swaps on Base today, solve the matching problem directly. Instead of waiting to find a specific counterparty, you trade against a shared pool of liquidity that is always available, with the atomicity guarantee coming from a single chain's transaction rules instead of a coordinated dance across two.

The short version

An atomic swap uses a hash time locked contract to let two people trade assets across separate blockchains without a middleman, by making sure either both sides of the trade complete or neither does. It was a clever and important idea in a world where blockchains could not otherwise interact. Swapping on Base works differently and more simply, because the entire trade happens inside one transaction on one chain, enforced directly by the network rather than by a timed handshake between two of them. The goal, all or nothing execution, is the same. The path to get there has just gotten much shorter.

Sources: Cross-chain Atomic Swaps Using Hash Time-Locked Contracts, sCrypt, Understanding HTLCs: The Engine of the Lightning Network, Lightspark, Atomic cross-chain trades explained, DEV Community

Ready to try it yourself?

Create a non-custodial wallet on Base in seconds. No account, no sign-up.

Open the web app