Skip to main content
This walkthrough runs one complete private payment and explains what happens at each step. It uses a Node.js script so you can see every result, and the same calls work unchanged in a browser. What you will do: open a Cloak account, quote costs, shield 2 USDC, send 1 USDC privately, and withdraw it back to a public address. Time: about 10 minutes. Cost: the withdrawal fee (about 0.45 USDC) plus Solana network fees.

Prerequisites

  • Node 22 or later.
  • A mainnet RPC URL. Any provider works; the public endpoint is rate-limited and may fail some calls.
  • A Solana keypair file with at least 2 USDC and 0.01 SOL. Cloak runs on mainnet only, so use a wallet you can afford to experiment with.

Step 1: Open the account

Put the setup in one module that every step imports:
setup.ts
step1.ts
What happened. The key signed the fixed Cloak account message, and the SDK derived the account from the signature: its spending key, its viewing key and the cloak_ address. The same key always opens the same account. Nothing was sent to the chain.

Step 2: Quote before moving money

step2.ts
The fee above was observed on mainnet on 2026-11-30 and follows the pool’s live config. What happened. Quotes are read-only. Shields and private sends carry no protocol fee. A withdrawal pays the pool’s fee, read live from chain, on top of the amount, so exactly 1 arrives.

Step 3: Shield 2 USDC

step3.ts
What happened. The SDK created a note worth 2 USDC owned by the account, proved it, and the key signed and paid for one Solana transaction. On chain, anyone can see 2 USDC entering the USDC pool from this wallet. They cannot see the note.

Step 4: Send 1 USDC privately

Send to your own cloak_ address here, or to a friend’s. Run each step with npx tsx stepN.ts.
step4.ts
What happened. The SDK spent the 2 USDC note and created two new ones: 1 USDC for the recipient and 1 USDC of change. The request was signed by a key derived from the account, not by the wallet, and was submitted for you. On chain, an observer sees a transaction in the pool with a public amount of zero: no amount, no sender, no recipient.

Step 5: Withdraw 1 USDC

step5.ts
What happened. Exactly 1 USDC arrived at the wallet, and the fee came out of the private balance. The withdrawal is public: the amount and the recipient are visible, but not which deposit funded it.

What you built

Next steps

Next.js application

The same flow in a browser, with a connected wallet.

Wallet integrations

Phantom, Privy, hardware and smart wallets.

Notes and balances

Where the notes live and what to back up.

Error codes

What each failure means and whether to retry.