Skip to main content
A minimal but complete Next.js (App Router) application. The user connects Phantom, Solflare, Backpack or any Wallet Standard wallet, opens their private balance, shields USDC and sends it privately. Every file below was built with next build against @cloak.dev/sdk 0.2.20 and loaded in a browser without errors.

Prerequisites

  • Node 22 or later.
  • A mainnet RPC URL. See Network and RPC.
  • A wallet with a few USDC and a little SOL, to try a shield.

1. Create the app and install

Pin @solana/web3.js@^1.99. The wallet adapter packages require web3.js 1.x, and an unpinned install now resolves to a newer major that conflicts with them.
.env.local
No next.config changes are needed. The build prints a Critical dependency warning from the prover’s worker library; it is harmless.

2. Wallet providers

app/providers.tsx
app/layout.tsx

3. The Cloak hook

Opens the account on an explicit click, because it asks the wallet to sign. It also starts the circuit download when the page mounts, so the first shield does not wait for it.
hooks/use-cloak.ts

4. The UI

components/private-balance.tsx
app/page.tsx

5. Run it

Open http://localhost:3000, connect a wallet, and click Open private balance.

Notes for production

  • Bundle size. The SDK and the prover add about 1.6 MB to the page that imports them. Load the private balance UI with next/dynamic on the routes that need it.
  • RPC key. NEXT_PUBLIC_ values ship to the browser. Use a domain-restricted RPC key, or proxy RPC through a route of your own.
  • Content-Security-Policy. Allow your RPC, https://api.cloak.ag and https://storage.googleapis.com in connect-src, and 'wasm-unsafe-eval' in script-src.
  • Storage. In the browser, createCloak keeps its records in localStorage. Offer users an encrypted notes backup. See Balances.
  • React (Vite): the same components without Next.js.
  • Privy: the same app with email and social login.