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
- The taker requests live quotes from the maker over WebSocket (each
quote_responsecarries anrfq_id). - The taker calls
POST /api/v1/swaps/init— the maker locks the exchange rate and returns aswapstring, apayment_hash, and anaccess_token. Theaccess_tokenis returned only once — store it alongside the payment hash, as it is required to poll the swap status later. - The taker’s RGB Lightning Node whitelists the
swapstring(authorising it to route through the node). - The taker calls
POST /api/v1/swaps/execute— the maker initiates the HTLC. - The Lightning Network routes the HTLC: the maker reveals the preimage to claim BTC, which simultaneously releases the RGB asset to the taker.
- If either party fails to complete within the HTLC timeout, both sides’ funds are returned automatically.
- The taker polls
POST /api/v1/swaps/atomic/statuswith thepayment_hashand theaccess_tokenfrom step 2. A missing or invalid token yields a uniform404 Swap not found.
Sequence Diagram
Endpoints Used
WebSocket Environments
Replace
{client_id} with a unique identifier for your session.