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.
mnemonicSignertakes your swap mnemonic. A wallet that keeps its seed elsewhere implementsSwapSigner. - 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 withget,put,list, andnextIndex.MemoryStoreis for tests only.
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 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
phases()yields every phase change and ends on a final phase. Checkswap.phaseafterwards.settled()resolves with the record when the swap settles, and rejects with aSwapErrorif it is refunded or fails.
resume() runs. Keep following until it ends. See Swap states for every phase.
Resume at startup
Callresume() every time your app starts, before anything else.
TypeScript
resume() does not wait for funding or confirmations. On mobile, call it again whenever the app returns to the foreground.
Errors
Failures are aSwapError 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.