Skip to main content
KaleidoSwap executes swaps atomically using the client’s RGB Lightning Node:

Atomic Swaps

The Desktop App uses Hash Time-Locked Contracts (HTLCs) to execute swaps atomically over the Lightning Network. Both sides lock their assets simultaneously — either the full swap completes or both sides get their funds back. There is no counterparty risk. This is the same mechanism behind the first ever RGB asset swap on Lightning mainnet.

How It Works

  1. The taker requests live quotes from the maker over WebSocket (each quote_response carries an rfq_id).
  2. The taker calls POST /api/v1/swaps/init — the maker locks the exchange rate and returns a swapstring, a payment_hash, and an access_token. The access_token is returned only once — store it alongside the payment hash, as it is required to poll the swap status later.
  3. The taker’s RGB Lightning Node whitelists the swapstring (authorising it to route through the node).
  4. The taker calls POST /api/v1/swaps/execute — the maker initiates the HTLC.
  5. The Lightning Network routes the HTLC: the maker reveals the preimage to claim BTC, which simultaneously releases the RGB asset to the taker.
  6. If either party fails to complete within the HTLC timeout, both sides’ funds are returned automatically.
  7. The taker polls POST /api/v1/swaps/atomic/status with the payment_hash and the access_token from step 2. A missing or invalid token yields a uniform 404 Swap not found.

Sequence Diagram

Endpoints Used

WebSocket Environments

Replace {client_id} with a unique identifier for your session.

SDK Integration

The SDK handles the WebSocket, init, and execute steps for you:

Swap APIs

Endpoints for atomic swap init and execute

Market APIs

Endpoints for quotes and market data

SDK Examples

End-to-end code examples for the atomic swap flow

Error Handling

Handle swap failures and edge cases