Skip to main content
KaleidoSwap is the shortest way to swap. You name what you pay and what you receive. The SDK prices the route, checks the maker’s answer, saves the swap, and then claims or refunds on its own. The only step that stays yours is the payment: paying the invoice or funding the lockup from your own wallet. The SDK holds no keys of its own and never moves your funds.

Routes

Chain swaps, L-USDT, USDT-RGB, Arkade, and pay-through are not served by this API yet. A quote for one of them comes back as a pair_unavailable refusal. Use the swap engine and the guide for that route.

Set up

createKaleidoSwap loads the WebAssembly binary itself, so you do not call init(). Build one KaleidoSwap per process and share it. Two things are yours to provide:
  • A signer, which derives each swap’s key and secret. mnemonicSigner takes your swap mnemonic. A wallet that keeps its seed elsewhere implements SwapSigner.
  • A store, which keeps each swap’s record and the counter of used swap indexes. FileStore (Node and Python) keeps one JSON file per swap in a directory you choose. In a browser, or to use your own database, pass any object with get, put, list, and nextIndex. MemoryStore is for tests only.
The store is as important as the mnemonic. Read the store rules before you ship.
Optional settings: makerUrl, bitcoinEsploraUrl, liquidEsploraUrl, pollIntervalMs, makerTimeoutMs, feeSatPerVb, quoteTtlMs, and reverseTimeoutHeadroom. Each has a default for the network.

Quote

Each side is an asset and the layer it lives on, written <layer>:<asset>.
A refusal is a value, not an error: the maker will not trade this pair or this amount right now. A quote carries fromAmount, toAmount, fees (maker and miner), limits, and expiresAt. In TypeScript, amounts go in as a bigint, a safe-integer number, or a decimal string, and come back as bigint.

Start

start checks both addresses against the asset and the network before it contacts the maker. It then checks the maker’s answer against your key, your secret, and the quoted terms, and saves the swap before it returns. Nothing is paid yet. swap.action is what you do next: pay invoice, or send exactly fundingAmount sats to fundingAddress in one transaction.

Follow the swap

Following a swap is what moves it: the SDK claims when the maker’s lockup confirms, and refunds when a swap you funded fails.
  • phases() yields every phase change and ends on a final phase. Check swap.phase afterwards.
  • settled() resolves with the record when the swap settles, and rejects with a SwapError if it is refunded or fails.
A swap moves only while something follows it or resume() runs. Keep following until it ends. See Swap states for every phase.

Resume at startup

Call resume() every time your app starts, before anything else.
TypeScript
It moves every open swap one step, claiming what can be claimed and refunding what can be refunded, and returns a report: resume() does not wait for funding or confirmations. On mobile, call it again whenever the app returns to the foreground.

Errors

Failures are a SwapError with a code. Narrow it with isSwapError (sdk.Error.Swap in Python).

The swap engine

KaleidoSwap is built on the swap engine: SwapClient, SwapMasterKey, and SwapScript. The engine is the same package and stays fully supported. Use it when you want to own every step, or for a route this API does not serve yet: Do not drive the same swap from both. A swap started with KaleidoSwap is claimed and refunded by KaleidoSwap.