Skip to main content
This page is written against @cloak.dev/sdk 0.2.20. Catch the typed errors below instead of matching message strings: the classes and codes are the stable surface, the wording is not.

createCloak errors: CloakCallError

Every call on the object createCloak returns throws one error type, CloakCallError (a CloakError), and it carries what a caller acts on:
  • code: stable and dotted (payout.refused, wallet.rejected, deposit.finish_failed). Match on it with isCloakCallError(e, code), which also matches every code under a prefix (isCloakCallError(e, "payout") is any payout.*).
  • retryable: whether the same call can succeed if it is made again.
  • moneyAt and next, when money is in flight: where it is now, and what happens to it. The message already includes both, written for a person.
A deposit or payout that stopped halfway is finished by the SDK itself (on the next start, or with cloak.resume()), which is why many in-flight errors are retryable with a next that says so.

Every CloakCallError code

Generated from the 0.2.20 source. “Retryable” is the error’s own retryable flag; trust the flag on the instance over this table. Two errors that are not CloakCallError can also come out of createCloak: WalletSignatureChangedError (the wallet now signs the account message differently than when the account was set up on this device) and StoredAccountRequiredError (the wallet cannot sign repeatably). Catch them by name.

The free functions’ errors

The free functions (transact, transfer, partialWithdraw, …) expose three layers:
  1. CloakError (runtime SDK operations, with a category and a retryable flag)
  2. Typed errors for the outcomes a caller must act on: RootNotFoundError, UtxoAlreadySpentError, SanctionsQuoteError, RelayInternalError, SettlementVerificationError, TransactionConfirmationError
  3. parseError / parseTransactionError (user-facing normalization)

CloakError

Most app flows should treat retryable === true as backoff-eligible.

Typed errors

confirmTransactSettlement re-checks a signature from chain state when an outcome was reported as unknown.

Persist the notes before you report success

transact, transfer, partialWithdraw, swapUtxo and swapWithChange all return result.outputUtxos, and the change note among them is the user’s remaining shielded balance. Outputs with amount === 0n are padding and can be skipped. fullWithdraw leaves nothing shielded. The notes the SDK builds for you are derived from your nk and a salt published in the encrypted chain note, so a lost change note can be found again by a scan (recoverNotesFromIndex, scanTransactions). The exception is a transfer’s change: it is output 1, the chain note describes only output 0, so a scan cannot learn its amount and the note is spendable again only once you supply that amount. Writing it down is still the fast path and gives you the leaf index at once. The notes that cannot be found again are the ones built with createUtxo (by you, or by a client that predates recoverable change), whose blinding is random and written nowhere, and notes owned by a random generateUtxoKeypair() key you did not keep. Those are unspendable by anyone if the only copy is dropped. This is an error-handling concern because every example below is a try/catch. The catch is the failure path; the tail of the try is the success path, and that is where the write belongs. saveNotes, dropNotes and saveSwapRefund in these snippets are your own storage, not SDK exports; Where your notes live between sessions covers what to build them on.

When fullWithdraw merges first

The circuit spends at most two notes per transaction, so both fullWithdraw and partialWithdraw consolidate first when you pass three or more inputs. Each consolidation round is its own on-chain transaction: it spends the two smallest notes and creates one merged note owned by your ownerUtxoKeypair. onProgress fires Consolidating notes (n remaining)... once per round, and that string is the signal a caller gets that consolidation is happening at all. Rounds that land are permanent, and the failure is what makes this an error-handling problem. If a later round or the final withdrawal throws (stale-root retries exhausted, a rejected wallet approval, a submission failure, a closed tab), then the two notes that round consumed are spent, the merged commitment is in the tree, and the call returned nothing, so there is no result.outputUtxos to write down. The merged note is not destroyed. Its blinding is derived from your nk and a salt the round published in its chain note, and the merged note is output 0, whose amount that chain note carries, so a rescan with nk finds it again (recoveredChangeNotes). Until you rescan, though, your app does not know it exists, and retrying with the original inputUtxos fails: the first merge round preflights their nullifiers and throws UtxoAlreadySpentError. What you can do, in order of usefulness:
Consolidating yourself is the only option that prevents the gap rather than recovering from it. Prefer it in any flow where the user can hold more than two notes.

Unauthorized and bare 401 on a send, withdraw or swap

Every request Cloak submits for you carries a signed sender, and every way that can go wrong arrives as the same opaque rejection. explainRelayAuthRejection turns one into user-facing prose, and returns null for anything that is not an authentication rejection, so it is safe to call unconditionally:
Two of the causes are not a bug in your code at all: an approval dialog left waiting, and a wrong clock on the user’s machine. Both are recoverable by retrying, and nothing was submitted for the request that was rejected. That is not the same as nothing having been submitted: with three or more inputs the rejection can arrive on a round that follows landed consolidation transactions, so reconcile with verifyUtxos before retrying rather than reusing inputUtxos. The full contract, including how to supply a signer at all, is in Request authentication. A call that has no usable signer never reaches the network. It throws up front, before any proof is generated, with a message that begins Cloak <flow> requires an authenticated sender (for a transfer, withdrawal or swap), <flow> requires options.ownerUtxoKeypair (a spend flow with no owner key), or Viewing key registration is mandatory (no nk, or nothing to sign the registration challenge). Those are setup mistakes, not runtime failures: fix the options rather than catching them.

Stale Merkle root (0x1001)

Use helpers for RootNotFound detection:
SDK note and UTXO flows already include retry loops (maxRootRetries); this usually appears only after retries are exhausted.

On-chain error message mapping

ShieldPoolErrors maps known custom program codes:

User-facing normalization

Practical retry strategy

  • Retry network and service failures with exponential backoff.
  • Avoid retrying deterministic validation failures.
  • On stale-root errors, rebuild proof data before retrying.
  • Never retry a SettlementVerificationError whose outcome is not "not-landed".

UTXO stale-root retry template

transact, partialWithdraw and fullWithdraw already retry a stale root internally, so an outer loop is only for the case where those retries are exhausted:
This template reuses inputUtxos on every attempt, which is safe only while that array holds one or two notes. With three or more, attempt 1 can land consolidation transactions before it throws, and attempt 2 then spends notes that are already nullified: the first merge round preflights them and throws UtxoAlreadySpentError instead of retrying. Consolidate down to two notes yourself before entering a loop like this, as in When fullWithdraw merges first. Swap partialWithdraw for transact, transfer, swapUtxo or swapWithChange and the loop is unchanged, but the tail still has to run: each of those returns a change note too, and the two swap helpers add a refund authorization. fullWithdraw is the only substitution that can skip the tail, and only when it is given one or two notes, because that is when it leaves nothing shielded and performs no merges of its own.

Security logging rule

Never log full notes/UTXOs with secrets. Log only non-sensitive identifiers (commitment prefix, leaf index, request ID, and tx signature when needed for support).