Core APIs
transact(params, options)transfer(...)partialWithdraw(...)fullWithdraw(...)swapUtxo(...)swapWithChange(...)
@cloak.ag/sdk.
Transaction semantics
externalAmount rules:
> 0: public deposit into the pool< 0: public withdrawal from the pool0: fully shielded transfer
264-byte public inputs and submits to relay /transact.
Fees
gross = abs(externalAmount)when withdrawing/swappingfee = 5_000_000 + gross * 3 / 1000net = gross - fee- deposits have no protocol fee but still must satisfy min deposit (
10_000_000lamports)
Create UTXOs
Deposit example (transact)
Withdraw and transfer helpers
partialWithdraw/fullWithdraw use /transact with negative externalAmount.
Swap example (/transact_swap)
swapWithChange sends TransactSwap payload (proof + 264-byte public inputs + swap params) to relay /transact_swap.
Viewing-key registration requirements
- Default behavior enforces viewing-key registration before protocol txs.
TransactOptions.enforceViewingKeyRegistrationdefaults totrue.- Registration signs fixed sign-in message and posts to
/viewing-key/register.
Risk-oracle deposits
When deposits require Range/Switchboard validation, include:riskOracleQueueriskQuoteUrl(orgetRiskQuoteInstruction)
GET /risk-quote is not implemented (501), so provide your own quote backend or direct instruction callback.
If deposit account list is too large for legacy transactions, use V0 + addressLookupTableAccounts.
Operational notes
- Amounts use
bigintin the UTXO API. - Proof retries are built in for stale roots (
0x1001). - Relay-backed Merkle reconstruction (
/commitments) is preferred for older indices. - Optional
cachedMerkleTreehelps sequential txs avoid extra rebuild/fetch. - Optional
useUniqueNullifiershelps local/surfpool repeated test runs.
Verification commands
Run fromsdk/:
Troubleshooting
Invalid public inputs size: relay expects264bytes, not232.RootNotFound/0x1001: regenerate proof with fresh root (SDK retry usually handles this).0x1020in local repeated runs: setCLOAK_UNIQUE_NULLIFIERS=1.viewing key not found: re-run a transaction with registration enabled, then rescan history.
Next
- Protocol internals: Shield Pool Program
- Relay routes and payloads: Relay API
- Full SDK exports: API Reference