This deep dive expands on the trustless transaction concepts from "Escrow without a company." It covers how atomic swaps work using hash time-locked contracts (HTLCs) โ the primitive that makes cross-chain trading possible without an exchange. This is technical content for developers and the deeply curious.
An atomic swap lets two parties trade coins on different chains without handing their funds to an exchange. The "atomic" part means the trade either completes in full or does not happen at all. There is no moment where one side has paid and the other can walk away.
The hash lock
The core primitive is a hash time-locked contract, or HTLC. One party locks funds with a condition: the money can be claimed by anyone who reveals a secret value whose hash matches a known hash. The other party locks the matching asset with the same hash on their chain.
When the first party reveals the secret to claim the second asset, the secret becomes public. The second party can then use it to claim the first asset. If one side stalls, a timelock refunds the funds after a deadline. The two legs are linked by the same secret and protected by the same kind of timeout.
Neither party needs to trust the other's custody. The contract enforces the trade, and if it does not complete, the funds return. That is a stronger guarantee than a centralized exchange, where the exchange holds the keys.
Why BCH fits
BCH has the pieces an HTLC needs: hash locks, timelocks, and cheap transactions. Low fees matter because an atomic swap is at least two transactions. On BCH, the fee is usually a rounding error, so even small swaps make sense.
CashTokens make the idea more general. A swap can exchange BCH for a token, or two tokens for each other, using the same UTXO model. The contract can inspect token categories and amounts, so the trade can be conditional on the right asset arriving. That is the foundation of peer-to-peer trading without a centralized order book.
Why it works
The hash lock and timelock are the whole trick. The same secret unlocks both legs, and the deadline returns the funds if the trade does not complete. Neither party can walk away with both assets, and neither has to trust the other's custody. The contract enforces the outcome.
The swap is visible on-chain, like any BCH transaction. Use fresh addresses and a wallet you trust, and the trade stays between the parties. For a community that wants peer-to-peer money, a peer-to-peer way to trade it is a natural extension.
Counterparties can meet through a peer-to-peer network, a community, or an order-book service that never takes custody. The settlement is atomic; the discovery layer is just how the two sides find each other.
The point of the primitive
The important shift is custody. A centralized exchange is convenient because it holds both sides of the trade and updates a database. An atomic swap replaces that database with a cryptographic link. The parties keep their keys until the trade, and if the trade does not complete, the funds return.
Exchanges remain useful for other services, and atomic swaps give people an alternative for trades that do not need a custodian. For a community that wants peer-to-peer money, having a peer-to-peer way to trade it is a natural extension.
For more on the primitives atomic swaps build on, see The script under every wallet and Covenants: rules that follow the coin.
We do not provide financial advice.