Skip to main content
A private swap spends SOL notes from the private balance, swaps through Jupiter, and delivers the output token to a public token account. The swap is not linked to the wallet that funded the balance. Swaps are a low-level feature: createCloak does not offer them.

How a swap works

  1. The client proves a spend of SOL notes and submits it. The program escrows the SOL, minus the pool’s fee, in a swap state account (TransactSwap).
  2. A follow-up transaction executes the Jupiter route and delivers the output to recipientAta. It must deliver at least minOutputAmount.
  3. If the swap cannot execute before its deadline, the escrow becomes reclaimable as a refund note.

Prerequisites

  • The low-level setup: a CloakRpc, ownerUtxoKeypair and nk from a persistent seed, and your own note storage. See Low-level API.
  • SOL notes in the private balance.
  • A Jupiter quote for the minimum output. The SDK does not quote; get one from Jupiter for the swap amount and apply your slippage.

Swap

Persist two things. outputUtxos is the change. refund is the authorization that reclaims the principal if the swap times out. Because chainNoteViewingKeyNk was passed, discoverSwapRefunds can rebuild a lost refund from nk, but storing it is the fast path.

From a browser wallet

Replace depositorKeypair with signMessage and walletPublicKey from the wallet adapter. A swap re-proves on every stale-root retry, and each proof is a new request the wallet must approve. Cap the prompts with maxWalletApprovals (default 5). The full variant is in Low-level API.

Tuning