An atomic swap is a direct trade of one cryptocurrency for another between two people, carried out through a cryptographic contract on each blockchain rather than through an exchange. The word “atomic” captures the guarantee: the swap either completes in full on both sides or it does not happen at all, and neither party can walk off with both deposits. No custodian holds the funds in the middle, and no account, identity verification, or trusted intermediary is involved. In exchange for that, you take on real technical complexity and some risks that exchange users never have to think about.
The Contract That Makes It Work
Every atomic swap runs on a Hashed Time Lock Contract, or HTLC. The contract locks funds behind two conditions at once. The first is the hashlock: the coins can only be released to someone who produces a specific secret value whose cryptographic hash matches the one stored in the contract. The second is the timelock: a hard deadline after which, if nobody has produced that secret, the funds automatically return to the person who deposited them.1Interledger Foundation. Hashed-Timelock Agreements
Two HTLCs, one on each blockchain, are set up with the same hash. That shared hash is what ties the two sides together. The only way to claim the coins on one chain is to reveal a secret that, once revealed, lets the counterparty claim the coins on the other chain.2Lightning Engineering. Hashed Timelock Contract (HTLC) If the secret is never revealed, both timelocks eventually expire and both deposits go home.
How a Swap Plays Out
Take two traders, Alice and Bob, who want to trade coins on two different blockchains. Alice initiates and Bob participates. The sequence runs like this:
- Alice picks a random secret value and runs it through the agreed hash function. She keeps the secret to herself and sends Bob the hash.
- Alice creates an HTLC on her blockchain and deposits her coins into it. The contract says: anyone who can present the secret matching this hash before the timelock expires can take these coins.
- Bob watches Alice’s chain, confirms her contract is live, and then creates his own HTLC on his blockchain using the same hash. He locks his coins under the same cryptographic condition, but with a shorter timelock than Alice’s.
- Alice reveals the secret to Bob’s contract and claims his coins. By doing that, she publishes the secret on Bob’s blockchain, where anyone can read it.
- Bob picks the secret up from his own chain and uses it to claim Alice’s coins before her longer timelock runs out.
Alice cannot take Bob’s deposit without exposing the one piece of information Bob needs to take hers.3Chainlink. What Is an Atomic Swap? If she never claims, both contracts expire and each side refunds. There is no path where one person walks away holding both sets of coins.
What Has To Be True Before You Can Do One
Not every pair of blockchains supports atomic swaps, and the preconditions matter more than most introductions let on.
Both chains have to support the same cryptographic hash function inside their transaction scripts, such as SHA-256. If the two networks use incompatible hashing, the shared-hash trick that holds the swap together simply does not work.4Decred Documentation. Atomic Swaps
Ordinary wallets cannot build HTLCs. You need wallet software or a decentralized platform that explicitly supports them. Both parties enter their public addresses on each chain, the amounts, and the contract duration. A mistyped hexadecimal address means the coins are gone, because no support team can reverse the transaction.
The two timelocks have to be asymmetric. The initiator’s timelock must be meaningfully longer than the participant’s. If both expired at the same moment, the initiator could wait until the last second, grab the participant’s coins by revealing the secret, and then refund their own deposit before the participant had time to use that revealed secret. The gap needs to cover block confirmation times, network delays, and fee spikes on both chains.
Then there are fees. A swap normally produces at least four on-chain transactions, two to lock and two to claim or refund, and each one pays the standard network fee on its chain. Those fees come due whether the swap succeeds or ends in refunds, so you budget for them on both sides before you start.
On-Chain Versus Off-Chain Swaps
On-chain swaps happen directly on the main ledgers of both cryptocurrencies. Every lock, claim, and refund is a normal transaction that waits for block confirmations and pays mining fees. A Bitcoin-to-Litecoin swap means waiting for confirmations on both sides. Bitcoin averages about ten minutes per block and typically wants six confirmations for finality, which runs about an hour on its own. Litecoin confirms faster at roughly 2.5 minutes per block, but the combined wait across both chains easily tops an hour in practice. Everything is permanently recorded on each chain.
Off-chain swaps run on a secondary layer such as the Lightning Network, which sits on top of a base blockchain. The parties use pre-existing payment channels instead of broadcasting each step to the whole network, and only the final balances settle on the main chain when the channels are eventually closed.5Lightning Engineering. Lifecycle of a Payment Channel These swaps are much faster and cheaper, but both parties need active channels with enough capacity, which rules out spontaneous trades with strangers.
When Things Go Wrong
Swaps fail more often than clean descriptions imply. A counterparty goes offline, changes their mind, or lets the clock run out. In every case, nothing is stolen, but funds get temporarily frozen.
If the participant never locks, the initiator waits for their own timelock to expire and then broadcasts a refund transaction that returns the coins to an address they control. The same works in reverse if the initiator locks but never claims. Both deposits come back through refund transactions once the timelocks run out.6Chainlink. Atomic Cross-Chain Transactions Explained The cost is the wait. Depending on how the timelocks were set, your capital can be stuck for hours or days, and in a volatile market that frozen window has a price even though you get the coins back.
The Free Option Problem
Once both sides have locked funds, the initiator holds all the leverage. They can watch the exchange rate and decide whether to complete the swap. If the market moved in their favor, they claim. If it moved against them, they let the timelock expire and refund. Cryptographic researchers have formally proven that this turns the swap into the equivalent of an American Call Option that the initiator gets for free, while the participant carries all the price risk for the length of the timelock.7arXiv. On the Optionality and Fairness of Atomic Swaps Some newer protocols try to blunt this by requiring both parties to post a “griefing premium” as collateral that is forfeited if they abandon the swap, at the cost of added complexity.8Schloss Dagstuhl – Leibniz-Zentrum für Informatik. 4-Swap: Achieving Grief-Free and Bribery-Safe Atomic Swaps Using Four Transactions
Griefing and Miner-Level Attacks
A griefing attacker locks nothing, or locks and walks away, specifically to freeze the counterparty’s capital through the full timelock. They do not profit directly; they inflict costs: locked funds, missed opportunities, and the fees paid for lock and refund transactions.8Schloss Dagstuhl – Leibniz-Zentrum für Informatik. 4-Swap: Achieving Grief-Free and Bribery-Safe Atomic Swaps Using Four Transactions Combined with the free option problem, an attacker can grief selectively on the swaps that moved against them.
Miners and validators who control transaction ordering can also exploit swaps. A miner might censor a claim transaction long enough for the timelock to expire, or collude with participants to extract both deposit and collateral.9NDSS Symposium. He-HTLC: Revisiting Incentives in HTLC These sit inside the broader category of Maximal Extractable Value, where ordering power becomes profit, and on networks with public mempools, bots routinely scan for exactly these opportunities.10arXiv. SoK: The Evolution of Maximal Extractable Value, From Miners to Cross-Chain
Privacy Is Not What People Assume
Atomic swaps avoid the identity checks that centralized exchanges require, so they are often described as private. That picture is incomplete. The same hash value appears in the HTLCs on both blockchains, so anyone watching both chains can match the hashes and link the two sides of the trade, connecting your coins on one network to your coins on the other.4Decred Documentation. Atomic Swaps Exchanges know who you are but do not expose that cross-chain linkage publicly. Swaps do not collect your name but publish a cryptographic fingerprint any observer can follow. Different tradeoff, not more privacy.
Taxes and Regulatory Status in the US
The IRS treats swapping one cryptocurrency for another as a taxable disposition, no different from selling one coin and buying another. You recognize a capital gain or loss equal to the difference between your adjusted basis in what you gave up and the fair market value of what you received.11Internal Revenue Service. Frequently Asked Questions on Digital Asset Transactions Doing the trade through an HTLC instead of a centralized exchange changes nothing about this. You report on Form 8949, short-term or long-term depending on the holding period.12Internal Revenue Service. Instructions for Form 8949 (2025)
Recordkeeping is where swaps are genuinely harder than exchange trades, because no broker is sending you a 1099. The IRS wants records that establish the specific units you traded, their acquisition date and cost, and their fair market value on the day of the swap. For coins in self-hosted wallets, you need to identify the particular units being transferred in your own records no later than the time of the transaction.11Internal Revenue Service. Frequently Asked Questions on Digital Asset Transactions In practice that means logs of timestamps, wallet addresses, transaction IDs, and the price source used for fair market value. If your numbers cannot be substantiated, the standard accuracy-related penalty is 20% of the underpayment, rising to 40% for gross valuation misstatements.13Office of the Law Revision Counsel. 26 USC 6662 – Imposition of Accuracy-Related Penalty on Underpayments
On the regulatory side, FinCEN draws a line between users and exchangers of virtual currency. Someone who swaps coins for personal use is a user and is not a Money Services Business, so no Bank Secrecy Act registration, reporting, or recordkeeping applies. Someone engaged as a business in exchanging virtual currency for other virtual currency, real currency, or funds is an exchanger, treated as a money transmitter with the full set of registration and compliance obligations. The classification turns on the pattern and purpose of what you are doing, not on the fact that you used an HTLC to do it.14Financial Crimes Enforcement Network (FinCEN). Application of FinCEN’s Regulations to Persons Administering, Exchanging, or Using Virtual Currencies (FIN-2013-G001)