Atomic Swaps Without the Jargon

Atomic Swaps Without the Jargon

Technical

// Technical

Moving crypto between two different blockchains usually means trusting something in the middle. An exchange holds your coins, or a bridge locks them and hands you a wrapped version. Either way, for a window that lasts anywhere from seconds to hours, a third party controls your funds, whether that is a centralized custodian, a set of validators, or a multisig. And whoever can move your funds in that window can also freeze or lose them.

Atomic swaps remove that window. They let two people trade crypto across two chains with no custodian, no wrapped token, and no point where one side or an intermediary controls the funds. This piece covers what they are, how they work under the hood, where they still fall short, and why the model matters more than it might appear.

What is an atomic swap?

An atomic swap is a direct exchange of two different cryptocurrencies, often on two different blockchains, that happens without any trusted middleman. The word "atomic" is the important part. The trade either completes in full for both sides, or it does not happen at all. There is no in between state where one person gets paid and the other gets nothing.

All or nothing property is enforced by code, not by a company. You and your counterparty exchange native assets in p2p fashion, and the rules of the swap make it impossible for either of you to cheat the other.

How do atomic swaps work?

The mechanics sound complex but the idea is simple. Both sides lock their funds in contracts that can only be unlocked by a single shared secret. Revealing that secret to claim one side automatically exposes it for the other side. So the moment you take your half of the trade, your counterparty can take theirs. Neither of you can grab funds and run.

Here is the full sequence in action on Garden:

Atomic swap flow: user and solver lock and claim assets across two chains using a shared secret

The funds sit in a lock that only opens one of two ways. Either the trade completes through the secret, or the timer runs out, and everything goes back where it came from. That is the whole trick.

The role of HTLCs in atomic swaps

The lock doing all this work has a name. It is a Hash Time-Locked Contract, or HTLC. An HTLC is just a contract with two possible exits and nothing else.

Two ways out of an HTLC: hashlock releases funds with the secret, or timelock auto-refunds the sender

The hashlock is the first exit. Whoever can produce the secret that matches the stored hash gets the funds. The timelock is the second exit. If nobody produces the secret before a set deadline, the funds go back to the sender. Those two exits are the entire safety model. The contract has no power to send your funds anywhere else.

This is the piece that makes atomic swaps trustless; we have a full walkthrough of the evolution if you want to go deeper on how HTLCs work.

Onchain vs off-chain atomic swaps

Atomic swaps come in two flavours, and the difference is where the locks live.

Onchain atomic swaps put the HTLCs directly on the blockchains involved. This is the cross chain case most people mean when they say atomic swap. You are swapping a native asset on one chain for a native asset on another, and both locks are recorded on their respective chains. It is the most common setup and the one that powers cross chain Bitcoin swaps on Garden.

Off-chain atomic swaps run inside payment channels instead, the kind the Lightning Network uses. The same hashlock and timelock logic applies, but the swap settles inside a channel rather than on the base chain. Say you hold Bitcoin in a Lightning channel and you want Litecoin, and someone on the other side has the opposite need. Rather than each of you posting locks on the Bitcoin and Litecoin base chains and waiting for confirmations, the swap runs across your payment channels using the same secret and timelock trick. Nothing touches the base chain until a channel closes, so it settles in seconds and costs almost nothing. The catch is that you both need open, funded channels with liquidity on the right sides, so this suits small, frequent swaps far better than a one off move of size.

Atomic swaps vs bridges and wrapped tokens

This is where the model earns its keep. The usual way to move Bitcoin onto another chain is a lock and mint bridge. You send your BTC to the bridge, it locks the coin, and it mints you a wrapped version like WBTC on the other side. That wrapped token is an IOU. It is only worth something as long as the bridge still holds the real BTC and stays honest.

Atomic swaps skip the IOU entirely. You hand over a native asset and receive a native asset. Nothing gets wrapped, and nothing gets locked in a pile that an attacker can drain.

Atomic swap vs lock-and-mint bridge: native asset exchange with no custodian, versus locked BTC and a wrapped IOU

It removes the two failure points, custody and wrapping.

Benefits of atomic swaps

  • Self-custody
  • No counterparty risk
  • No wrapped token
  • No slippage

Limitations of atomic swaps

  • The swap waits on block confirmations, so it is slower than an instant trade. 
  • A swap only happens if someone takes the opposite leg. The classic version made you find that person yourself, though solver networks now handle this automatically; solver liquidity and inventory are constraints.
  • Hashlocks and timelocks are required on each chain, so the set of supported assets is narrower than a system that just mints wrappers.
  • Creates a free option, whoever holds the secret can walk away if the price moves against them mid swap, since their funds simply refund. 

Most of these used to be dealbreakers. Solver networks have largely solved the liquidity and counterparty problems, and penalties blunt the free option. What is left is mostly the waiting period, which is the honest cost of settling on real chains instead of trusting someone to settle for you.

What can you do with atomic swaps today?

The early tools were rough, since you had to find your own counterparty and both of you had to stay online and babysit the swap. That has changed. Modern protocols ask a simpler question, what do you want, and let a network of solvers compete to fill it. CoW Swap popularized this intent and solver model for same chain trading, and Garden applies the same one click experience on top of real atomic settlement using HTLCs for cross chain movement. You get a quote, you confirm, and you are done. No counterparty hunting, no staying glued to the screen, no wrapped tokens landing in your wallet, and the trustless guarantees stay intact while the work moves onto the solvers.

The easiest way to understand it is to run one. These are real atomic swaps you can do right now:

Frequently Asked Questions

Are atomic swaps safe?

The settlement is enforced by cryptography, not by trust. Either both sides of the swap complete, or both refund through the timelock. No third party holds your funds at any point, so the main risks that hit exchanges and bridges, custody and wrapped token backing, do not apply. The remaining risks are practical ones like waiting on confirmations and finding liquidity.

Do both parties have to be online during the swap?

In the original peer-to-peer design, yes, and that was a real pain. You both had to stay active to reveal and claim within the timelock windows. Modern protocols fix this with solver networks. A solver takes the counterparty role and handles its side automatically, so you sign once and the system carries the swap through. You are not stuck watching a screen.

What is the "free option" problem in atomic swaps?

Because the secret holder can simply let the swap expire and get refunded, they effectively hold a free option. If the price moves in their favour during the timelock they complete the swap, and if it moves against them they walk away at no cost. On a long timelock that option has real value, and it is unfair to the counterparty. Protocols counter it with fees, bonds, or penalties that make abandoning a swap more expensive than finishing it, which removes most of the incentive to game it.

Can an atomic swap be front run or sandwiched like a normal DEX trade?

The rate is fixed when both sides lock their funds, so there is no in flight price for a bot to manipulate the way it would on an AMM. That removes the classic sandwich attack. The secret does become public onchain when the first party claims, but by then the timelocks already protect both sides, so seeing the secret does not let anyone steal a leg.

Please note: The term atomic swaps gets used loosely. Plenty of protocols advertise atomic swaps while still routing your funds through a pool or a validator controlled vault mid swap. Those are atomic, the trade completes or fully refunds, but someone else holds your money in between, so they are not non-custodial. This article describes how atomic swaps work on Garden, built using HTLCs, where your funds stay in cryptography only you and your counterparty (solver) can access. If you are comparing options, do not stop at the word atomic. Check who holds your funds while the swap settles.

Last updated

Related Blogs