Prerequisites
- Node 22 or later,
@cloak.dev/sdk0.2.20. - A database with two tables: a key-value table for SDK state and a jobs table. Any database works; the code below talks to them through small interfaces you implement.
- In your secret store: the treasury account key (32 random bytes as hex) and a storage secret (32 random bytes as hex).
The jobs table
The worker
worker.ts
Why it is safe to restart
- Idempotency. Each job’s
refis derived from its id. After a crash, the worker picks the job up again andsendreturns the stored receipt withrepeated: trueinstead of paying again. - Unknown outcomes are not retried blindly.
ref.unsettledmeans a call started and never recorded its end, for example a process killed mid-payment. The worker parks the job for review. - State outlives the process.
encryptedStoragekeeps receipts, refs and open cross-chain orders in your database, encrypted, so the next process sees them.
Funding the treasury
Shield into the treasury from a wallet the organization controls, or have anyonesend to
cloak.address. To shield from a server-held key, open the same account with both the key and the
wallet: createCloak({ account, wallets: [fundingSigner], storage, rpc }), then
cloak.shield({ from: "solana", ... }).
Monitoring
Related
- Payroll
- Transaction history: reconcile payouts against the account’s history.