/bn-fhevm:fhevm-frontendfrom bn-fhevm
Used when building React frontends (Vite or Next.js App Router) that integrate with FHEVM confidential smart contracts. Covers the @zama-fhe/* SDK stack, ZamaProvider wiring, encrypt and decrypt hooks, ERC-7984 wrap and unwrap flows, and Next.js SSR or bundler configuration.
Ships in bn-fhevm. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Ship React/Next.js UIs that integrate with FHEVM confidential contracts. Covers the @zama-fhe/* SDK stack, ZamaProvider wiring, encrypt/decrypt hook flows, ERC-7984 shielding, and bundler/SSR configuration.
@zama-fhe/sdk@^3Two SDK families coexist in Zama's npm namespace:
@zama-fhe/relayer-sdk — what docs.zama.org currently documents (createInstance(SepoliaConfig), framework-agnostic). Targeted by older tutorials and the published fhevm-react-template.@zama-fhe/sdk + @zama-fhe/react-sdk — what npm install @zama-fhe/react-sdk resolves. Surface: ZamaProvider, hooks, RelayerWeb / RelayerNode. This skill targets the high-level family. Version pins and verification date live in references/package-stack.md.Concrete differences relative to docs.zama.org:
https://relayer.testnet.zama.org/v2 (note /v2), shipped in SepoliaConfig.10901.SepoliaConfig exported by @zama-fhe/sdk@^3; do not copy from the doc site.If a developer arrives from docs.zama.org and sees disagreement, this skill is correct against the npm registry — these values work against the v2 protocol. If you genuinely need the lower-level path, install @zama-fhe/relayer-sdk directly and call createInstance — out of scope for this skill.
The relayer re-encrypts a ciphertext under the user's ephemeral ML-KEM public key. Nothing is revealed on-chain; nothing is synchronous. The on-chain call returns a bytes32 handle; useUserDecrypt orchestrates the ML-KEM keypair, the EIP-712 signature, and the relayer round-trip to produce the plaintext client-side.
"use client" is mandatory in Next.js App Router (not in Vite)Every component that imports from @zama-fhe/react-sdk under Next.js App Router must declare "use client" at the top. FHE operations run in a Web Worker that relies on browser APIs (window, fetch, IndexedDB). Server-side rendering crashes on import. Transitive consumers of ZamaProvider must carry the directive forward even though ZamaProvider itself ships with "use client".
Vite (and any non-SSR React stack) has no Server Component boundary, so the directive does not apply — omit it in Vite files.
relayerUrl is not the RPC URLThe RelayerWeb config takes a relayerUrl (the HTTPS Zama relayer service for encrypt and decrypt requests) plus a network property (the Ethereum JSON-RPC for on-chain reads). The error message "wrong relayer url" fires regardless of which one is misconfigured — including the case where undici (Node's fetch polyfill) returns an ArrayBuffer instead of Uint8Array from response.bytes(). When this error appears, verify relayerUrl, network, AND the runtime's response-type behavior.
On-chain ACL: FHE.allow(ciphertext, userAddress) must have been called in the contract before the relayer will re-encrypt a handle for the user. Off-chain session credential: the wallet must have signed an EIP-712 permit covering the contract address (prime with useAllow([contractAddress]), check with useIsAllowed({ contractAddresses })). Both are required — useIsAllowed reports only the session side. Miss either and the relayer rejects with DecryptionFailedError and no clear root-cause indication.
ZamaProvider nesting order is fixed<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ZamaProvider relayer={...} signer={...} storage={...}>
<App />
</ZamaProvider>
</QueryClientProvider>
</WagmiProvider>
ZamaProvider calls useQueryClient() internally — QueryClientProvider must be an ancestor. WagmiSigner subscribes to wallet events via WagmiProvider. Swapping the order throws at mount.
useUserDecrypt is a React Query hook with mutation-grade side effects (EIP-712 signature, ML-KEM keypair, wallet prompt). Gating enabled on data readiness alone (enabled: hasHandle && hasSession) fires it on mount and surfaces unprompted wallet popups. Always gate enabled on a click-flipped userRequested boolean and reset it on handle change. usePublicDecrypt is already a mutation, no gate needed. Full diagnosis: AP-9 and references/ui-patterns.md.
The FHEVM semantics (principles 1, 3, 4, 5; every hook in references/hook-catalog.md) are framework-agnostic. The SSR/provider-shell patterns are Next.js App Router only; Vite gets a simpler parallel path.
| Concern | Next.js App Router (14+) | Vite (5+) / other React |
|---|---|---|
"use client" directive | required on every consumer (Principle 2) | not used — no Server Components |
Provider shell (next/dynamic + ssr: false) | required (see workflows/configure-build.md) | not needed — instantiate at module top |
| Env var syntax | process.env.NEXT_PUBLIC_<NAME> (literal only) | import.meta.env.VITE_<NAME> (literal only) |
| Env var prefix | NEXT_PUBLIC_ | VITE_ |
| Bundler config | next.config.mjs (Turbopack on Next 16, Webpack on 14/15) | vite.config.ts + vite-plugin-node-polyfills |
Dev server restart on .env edit | required | required |
| Dynamic env access bug | AP-7 (Next side) | AP-7 (Vite side) |
| Hydration mismatch risk | real — the shell avoids it | not applicable |
For stack-specific code, follow workflows/setup-provider.md Phase 5 (Next shell) or references/provider-wiring.md Variant 4 (Vite direct). Other stacks (CRA, Remix, TanStack Start) are either Next-App-Router-like (apply the shell pattern) or Vite-like (instantiate directly).
ZamaProvider with Wagmi + a signer + storage in a fresh React / Next.js / Vite app.useEncrypt to prepare an encrypted input bundle for a contract write.useUserDecrypt for a value where the current user has ACL access.usePublicDecrypt for a publicly-decryptable handle.useShield / useUnshield to wrap or unwrap between ERC-20 and ERC-7984.serverExternalPackages for this stack."wrong relayer url", WASM 404s, undici response-type issues, or silent decrypt failures.fhevmjs code to the @zama-fhe/* SDKs.fhevm-contracts.fhevm-testing.fhevm-setup.fhevm-overview.Step 1 — Task. Which task does the user's prompt match?
ZamaProvider + signer + storage in a new app.undici, silent decrypt, env var not inlined, zero-handle decrypt).If the prompt does not match any of these, explain the scope of this skill and suggest the closest alternative from When NOT to Use.
| User intent | Workflow | |-------------|----------| | 1, "setup", "provider", "zamaprovider", "wire" | `workflows/setup-provider.md` | | 2, "encrypt", "useencrypt", "input proof" | `workflows/encrypt-input.md` | | 3, "user decrypt", "useuserdecrypt", "reencrypt", "eip-712" | `workflows/user-decrypt.md` | | 4, "public decrypt", "usepublicdecrypt" | `workflows/public-decrypt.md` | | 5, "wrap", "unwrap", "shield", "unshield", "erc-7984" | `workflows/wrap-unwrap.md` | | 6, "bundler", "webpack", "turbopack", "ssr", "use client", "next.config", "vite.config", "vite-plugin-node-polyfills" | `workflows/configure-build.md` | | 7, "error", "debug", "wrong relayer url", "wasm 404", "undici", "silent decrypt", "env var undefined", "zero handle" | `workflows/debug-errors.md` | | 8, "deploy", "production", "csp", "coop", "coep", "wasm cache", "node runtime" | `workflows/deploy-to-production.md` |After reading a workflow file, follow it exactly. Do not invent steps.
| Package | Pin | Role | Install |
|---|---|---|---|
@zama-fhe/react-sdk | ^3.0.0 | React hooks + ZamaProvider | direct |
@zama-fhe/sdk | ^3.0.0 | Peer of react-sdk; hosts signer subpaths (/viem, /ethers) | direct |
@zama-fhe/relayer-sdk | resolved by @zama-fhe/sdk | Low-level WASM + relayer client | transitive only |
Install exactly two packages in dependencies. @zama-fhe/relayer-sdk is a regular dep of @zama-fhe/sdk and resolves automatically — do not list it directly. Node >=22. See references/package-stack.md for peer dependencies and pinning.
| Obsolete | Current | Source |
|---|---|---|
fhevmjs | @zama-fhe/relayer-sdk (low-level) or @zama-fhe/sdk (high-level) | 2024 rename |
FheProvider | ZamaProvider | react-sdk 2.x |
useDecrypt | useUserDecrypt | react-sdk 2.x |
FHE.requestDecryption | useUserDecrypt / usePublicDecrypt | react-sdk 2.x |
SepoliaZamaFHEVMConfig | SepoliaConfig | react-sdk 2.x |
Full deprecated catalog in references/anti-patterns.md.
Full hook surface (~60 hooks) lives in references/hook-catalog.md with the most-used contracts table at the top. Canonical signatures: node_modules/@zama-fhe/react-sdk/dist/index.d.ts.
| File | Purpose |
|---|---|
references/package-stack.md | Current versions, peer dependencies, Node requirement, wagmi 3.x requirement, forthcoming @fhevm/sdk rename |
references/hook-catalog.md | Public hooks grouped by purpose (encrypt, decrypt, token, wrap/unwrap, discovery, registry, delegation, activity); links to the canonical .d.ts for exact signatures |
references/provider-wiring.md | Complete nesting code including signer variants (Wagmi, Viem, Ethers) — subpath imports, class instantiation, next/dynamic + ssr: false shell |
references/anti-patterns.md | Gotchas with wrong → why-wrong → correct → verification |
references/ui-patterns.md | FHEVM-specific UX patterns: explicit-action decryption, handle display, decryption lifecycle states, ACL-denied recovery, encrypt UX, wallet rejection vs real error |
| Workflow | Input → Output |
|---|---|
workflows/setup-provider.md | Prompt about new-app setup → wired ZamaProvider with justified prop choices |
workflows/encrypt-input.md | Prompt about encrypting → useEncrypt call + transaction submission pattern |
workflows/user-decrypt.md | Prompt about reading user values → useAllow + useUserDecrypt chain |
workflows/public-decrypt.md | Prompt about public decrypt → usePublicDecrypt call + proof usage |
workflows/wrap-unwrap.md | Prompt about ERC-20 ↔ ERC-7984 → useShield / useUnshield orchestration |
workflows/configure-build.md | Prompt about build errors → Webpack / Turbopack / Next.js config fix |
workflows/debug-errors.md | Prompt with error message → taxonomy lookup + fix steps |
workflows/deploy-to-production.md | Prompt about production deploy → Node runtime, CSP for the relayer, WASM caching, COOP/COEP for multi-threaded WASM |
<contracts-workspace>/artifacts/contracts/<Contract>.sol/<Contract>.json) or kept identical to it. Hand-maintained ABIs that drift on the indexed flag silently corrupt event decoding — see AP-10.dependencies holds exactly two @zama-fhe/* packages: @zama-fhe/react-sdk@^3 and @zama-fhe/sdk@^3. @zama-fhe/relayer-sdk (transitive) appears only via npm explain @zama-fhe/relayer-sdk.>=3.0.0 (not the declared >=2). npm ls wagmi confirms."use client".@zama-fhe/react-sdk/wagmi, @zama-fhe/sdk/viem, @zama-fhe/sdk/ethers) and passed as instances (new WagmiSigner({ config })), not class references.RelayerWeb config is { transports, getChainId }, with each transport spreading a preset (SepoliaConfig / MainnetConfig / HardhatConfig). See AP-4.process.env.NEXT_PUBLIC_X (Next) or import.meta.env.VITE_X (Vite). See AP-7.useUserDecrypt call guards against the zero handle via isZeroHandle(handle). See AP-8 and workflows/user-decrypt.md Phase 1.5.useUserDecrypt call gates enabled on a userRequested boolean flipped by an explicit click, with a useEffect that resets the boolean on handle change. Never enabled: hasHandle && hasSession alone. See Principle 6, AP-9, and references/ui-patterns.md "Explicit-Action-Only Decryption".next/dynamic(..., { ssr: false }) shell. See workflows/setup-provider.md Phase 5a and workflows/configure-build.md § SSR shell. Vite: no shell; module-top mount.useEncrypt's type field uses plain string literals (type: "euint64") — no as FheTypeName cast. The discriminated union rejects the widened type.tsconfig.json compilerOptions.target is ES2020+ (BigInt literals). See workflows/setup-provider.md Phase 1.5.>=16: either (a) package.json scripts pass --webpack on every next dev / next build, or (b) next.config.* has a turbopack key. Turbopack is the default bundler in Next 16.next.config file is .mjs / .cjs / .ts as appropriate for package.json's "type" — a .js with require() under "type": "module" throws at load.vite.config file is .ts (recommended) or .mjs. Under "type": "module", a .js with require() or a .cjs that uses ESM imports breaks the same way as Next — keep the extension aligned with the package.json type.vite.config.ts includes vite-plugin-node-polyfills for Buffer (and optional globals). See workflows/configure-build.md Phase 3.fhevmjs, FheProvider, useDecrypt, FHE.requestDecryption, or SepoliaZamaFHEVMConfig.npm run build (Next) or npm run build runs to completion with no errors.workflows/configure-build.md) only surface at mount or interaction time. Prompt the user to run npm run dev, open http://localhost:<port> in a browser, open DevTools, and confirm:
ReferenceError, no Cannot find module, no [zama-sdk] DecryptCache.clearAll failed..wasm request returns HTTP 200.useZamaSDK() renders without throwing.NEXT_PUBLIC_<NAME>_ADDRESS (Next) or VITE_<NAME>_ADDRESS (Vite) — e.g. NEXT_PUBLIC_COUNTER_ADDRESS / VITE_COUNTER_ADDRESS.references/anti-patterns.md (opens in a new tab)references/hook-catalog.md (opens in a new tab)references/package-stack.md (opens in a new tab)references/provider-wiring.md (opens in a new tab)references/ui-patterns.md (opens in a new tab)workflows/configure-build.md (opens in a new tab)workflows/debug-errors.md (opens in a new tab)workflows/deploy-to-production.md (opens in a new tab)workflows/encrypt-input.md (opens in a new tab)workflows/public-decrypt.md (opens in a new tab)workflows/setup-provider.md (opens in a new tab)workflows/user-decrypt.md (opens in a new tab)workflows/wrap-unwrap.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (bootnodedev/zama-s2-bounty-skills) — no native marketplace selected
npx claudepluginhub p/bootnodedev-bn-fhevm10 skills in this plugin
/create-templateUse when scaffolding a new FHEVM workspace -- contracts, Next.js frontend, or Vite frontend. Copies the canonical bundled template (project/ or templates/frontend-{next,vite}/) into a target directory and customizes package metadata, env-var defaults, and the Sepolia RPC URL via an interactive AskUserQuestion wizard./fhevm-antipatternsUsed when reviewing, debugging, auditing, or pre-commit-checking FHEVM Solidity or client code. Catalogues the v0.11-era breaking renames (TFHE→FHE, SepoliaZamaFHEVMConfig→ZamaEthereumConfig, ConfidentialFungibleToken→ERC7984, TFHESafeMath→FHESafeMath, tokenURI→contractURI, isUserAllowed→canTransact), the removed FHE.requestDecryption API, deprecated fhevmjs, and high-frequency footguns (missing FHE.allowThis after state writes, view functions returning encrypted types, .env-based Hardhat secrets). Triggers on FHEVM code review, anti-pattern, audit, migration from pre-v0.9/v0.11, pre-commit check, ACLNotAllowed, EmptyDecryptionProof, or DeclarationError./fhevm-contractsUsed when writing, refactoring, or reviewing FHEVM Solidity contracts against the @fhevm/[email protected] API. Covers encrypted types (ebool, euint8..256, eaddress), FHE operations (arithmetic, comparison, FHE.select), the ACL lifecycle (FHE.allow, allowThis, allowTransient, isSenderAllowed, makePubliclyDecryptable), and the input-proof flow (externalEuint* + FHE.fromExternal). Triggers on FHEVM contract patterns, encrypted types, FHE.* library calls, ACL permissions, input proofs, ciphertext handles, ZamaEthereumConfig, or writing a confidential counter / voting / auction / vault contract.Other plugins' skills for the same job