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
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
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/dynamicon 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.agandhttps://storage.googleapis.cominconnect-src, and'wasm-unsafe-eval'inscript-src. - Storage. In the browser,
createCloakkeeps its records inlocalStorage. Offer users an encrypted notes backup. See Balances.
Related
- React (Vite): the same components without Next.js.
- Privy: the same app with email and social login.