Skip to main content
Privy creates a Solana wallet for a user at login, with no extension and no seed phrase. This guide wires a Privy embedded wallet into createCloak, so the same login gives the user a private balance. External wallets connected through Privy work the same way. Tested against @privy-io/react-auth 3.52.1 and @cloak.dev/sdk 0.2.20.

How it works

The embedded wallet is an ordinary ed25519 key held by Privy, so it signs the account message the same way every time. createCloak checks that on first use by signing twice and comparing, and refuses a wallet whose signatures differ instead of silently opening a different account.
Privy smart wallets are not Solana wallets. Privy’s smart wallets are ERC-4337 accounts on EVM chains. Use the embedded Solana wallet for Cloak. See Smart wallets.

Prerequisites

  • A Privy app with Solana embedded wallets enabled. Copy its App ID.
  • A Next.js (App Router) or React app.
  • A mainnet RPC URL and its WebSocket URL.
@stripe/stripe-js is needed by a Privy module that webpack (the Next.js default bundler) resolves at build time.
.env.local
NEXT_PUBLIC_ variables ship to the browser. Use an RPC key restricted to your domain, or proxy RPC through your own route. See Network and RPC.

1. Configure the Privy provider

Create Solana embedded wallets at login and give Privy a mainnet RPC. Privy’s Solana wallet hooks need the solana.rpcs entry.
app/providers.tsx
Wrap your root layout with <Providers>.

2. Get the embedded wallet

useWallets() from @privy-io/react-auth/solana returns ConnectedStandardSolanaWallet objects. Pass one to createCloak as it is. The SDK recognizes it and drives the wallet’s standard solana:signMessage and solana:signTransaction features.

3. Open the Cloak account

Keep the opened account in React state. Open it after an explicit user action, because it asks the wallet to sign.
hooks/use-cloak.ts
cloak.address is the user’s cloak_ address. The same Privy login opens the same Cloak account on any device, because the account comes from the wallet’s signature.

4. Shield, send and withdraw

components/private-balance.tsx
The shield asks the embedded wallet to sign one transaction. The wallet needs the USDC and a little SOL for the network fee. The send and any withdrawal do not prompt the wallet at all.

What the user sees

  • Signature prompts. Whether Privy shows its own confirmation for each signature follows your embeddedWallets.showWalletUIs setting, or the dashboard’s when unset.
  • First open. Two signatures of the Cloak account message, then the address appears.
  • Proof time. Each shield, send and withdrawal generates a zero-knowledge proof in the browser. The first one also downloads about 23 MB of circuit files. Show onProgress text, and warm the circuits on mount with verifyAllCircuits(getCircuitsPath()).

Funding the embedded wallet

A new embedded wallet is empty. A shield from Solana needs the token plus a little SOL for the network fee, paid by the wallet. Two ways around that:
  • Shield from another chain. If the user holds USDC on Base or Polygon in an EVM wallet, pass that wallet too and call shield({ from: "base", ... }). The Solana side needs no SOL. See EVM wallets.
  • Sponsor the deposit with the low-level API’s externalFeePayer. See Custom signers.
Privy’s own gas sponsorship only applies to transactions sent through Privy’s sign-and-send call. The SDK signs with the wallet and submits through your RPC, so that sponsorship does not cover Cloak shields.

Server-side Privy wallets

A Privy server wallet is a @solana/kit signer from createSolanaKitSigner in @privy-io/node. createCloak accepts it as a wallet and ignores its ability to send. See Custom signers.

Troubleshooting