A framework-agnostic SDK for building confidential dApps with Fully Homomorphic Encryption (FHE). Works with React, Vue, Vanilla JS, Node.js, and Next.js.
Experience the SDK across different frameworks:
|
Next.js nextjs.unifhevm.xyz |
React react.unifhevm.xyz |
Vue vue.unifhevm.xyz |
Vanilla JS vanilla.unifhevm.xyz |
Node.js nodejs.unifhevm.xyz |
π Complete SDK Documentation β
For detailed API reference, examples, and advanced usage, see the SDK documentation.
fhevm-react-template/
βββ packages/
β βββ fhevm-sdk/ # Universal FHEVM SDK
β β βββ src/
β β β βββ core/ # Framework-agnostic core
β β β βββ adapters/ # React, Vue, Vanilla adapters
β β β βββ internal/ # Internal utilities
β β β βββ storage/ # Storage abstraction
β β βββ README.md # Complete SDK documentation
β β
β βββ hardhat/ # Smart contracts & deployment
β βββ react/ # React example
β βββ vue/ # Vue example
β βββ vanilla/ # Vanilla JS example
β βββ nodejs/ # Node.js example
β βββ nextjs/ # Next.js example
β
βββ README.md # This file
Inspired by wagmi, this SDK provides familiar patterns for web3 developers:
// Wagmi (Ethereum)
const { data } = useContractRead({ ... });
// Our SDK (FHEVM)
const { instance, isReady } = useFHEVM({ provider, chainId });
const { encrypt, encryptUint32 } = useFHEEncrypt({ instance, signer, contractAddress });
const { decrypt, results, isDecrypting } = useFHEDecrypt({ instance, signer, requests });Single package with zero config - no need to manage @zama-fhe/relayer-sdk, @fhevm/mock-utils, or other dependencies. Everything is bundled and ready to use.
The SDK uses package.json "exports" for subpath imports:
| Import Path | Points To | Purpose |
|---|---|---|
uni-fhevm-sdk |
src/index.ts |
Core types and utilities |
uni-fhevm-sdk/react |
src/adapters/react/ |
React hooks |
uni-fhevm-sdk/vue |
src/adapters/vue/ |
Vue composables |
uni-fhevm-sdk/vanilla |
src/adapters/vanilla/ |
Promise-based API |
uni-fhevm-sdk/core |
src/core/client.ts |
Core client (advanced) |
uni-fhevm-sdk/storage |
src/storage/ |
Storage utilities |
This allows precise imports and better tree shaking.
npm install uni-fhevm-sdk ethersReact (Hooks):
import { useFHEVM, useFHEEncrypt, useFHEDecrypt } from 'uni-fhevm-sdk/react';
// Initialize
const { instance, isReady } = useFHEVM({ provider: window.ethereum });
// Encrypt
const { encryptUint32 } = useFHEEncrypt({ instance, signer, contractAddress });
const encrypted = await encryptUint32(42);
// Decrypt (with EIP-712 signature)
const { decrypt, results } = useFHEDecrypt({ instance, signer, requests: [{ handle, contractAddress }] });
await decrypt();
// Public Decrypt (no signature)
const { publicDecryptSingle } = useFHEDecrypt({ instance, signer });
const value = await publicDecryptSingle(handle);Vue (Composables):
<script setup>
import { useFHEVM, useFHEEncrypt, useFHEDecrypt } from 'uni-fhevm-sdk/vue';
// Initialize
const { instance, isReady } = useFHEVM({ provider: window.ethereum });
// Encrypt
const { encryptUint32 } = useFHEEncrypt({ instance, signer, contractAddress });
const encrypted = await encryptUint32(42);
// Decrypt (with EIP-712 signature)
const { decrypt, results } = useFHEDecrypt({ instance, signer, requests: [{ handle, contractAddress }] });
await decrypt();
// Public Decrypt (no signature)
const { publicDecryptSingle } = useFHEDecrypt({ instance, signer });
const value = await publicDecryptSingle(handle);
</script>Vanilla JS / Node.js / Next.js:
import { createFHEVMClient } from 'uni-fhevm-sdk/vanilla';
// Initialize
const client = await createFHEVMClient({ provider: window.ethereum });
// Encrypt
const encrypted = await client.encryptValue(42, 'uint32', { contractAddress, userAddress });
// Decrypt (with EIP-712 signature)
const results = await client.decrypt([{ handle, contractAddress }], signer);
// Public Decrypt (no signature)
const value = await client.publicDecryptSingle(handle);This repository includes 5 complete framework examples:
# Clone the repository
git clone <repository-url>
cd fhevm-react-template
# Install all packages from root
pnpm install
# Terminal 1: Start local Hardhat node
pnpm chain
# Terminal 2: Deploy contracts & generate ABI
pnpm deploy:localhost
# Terminal 3: Start your desired frontend
pnpm start:react # React (Vite) - http://localhost:5173
pnpm start:vue # Vue 3 - http://localhost:5174
pnpm start:vanilla # Vanilla JS - http://localhost:5175
pnpm start:nodejs # Node.js server - http://localhost:3000
pnpm start:nextjs # Next.js - http://localhost:3000Need to connect a wallet? Here's the pattern used in all our examples - just copy and use:
// React Hook
import { useState, useEffect } from 'react';
import { ethers } from 'ethers';
function useWallet() {
const [account, setAccount] = useState(null);
const [signer, setSigner] = useState(null);
const connectWallet = async () => {
const provider = new ethers.BrowserProvider(window.ethereum);
const accounts = await provider.send('eth_requestAccounts', []);
setAccount(accounts[0]);
setSigner(new ethers.JsonRpcSigner(provider, accounts[0]));
};
useEffect(() => {
// Auto-connect if already connected
if (window.ethereum) {
window.ethereum.send('eth_accounts', []).then(accounts => {
if (accounts.length > 0) connectWallet();
});
}
}, []);
return { account, signer, connectWallet };
}The SDK is built with a 100% framework-independent core:
- No React/Vue/framework dependencies in core logic
- Easy to add new framework adapters
- Works in Node.js, browser, any environment
| Framework | Implementation |
|---|---|
| React | Hooks: useFHEVM, useFHEEncrypt, useFHEDecrypt |
| Vue 3 | Composables: Same API, reactive Ref returns |
| Vanilla JS | Promise-based: createFHEVMClient |
| Node.js | Server-side encryption/decryption |
| Next.js | SSR-compatible with client components |
- Encryption: Encrypt values locally before sending to contracts
- User Decryption: Decrypt values with EIP-712 signatures (private to user)
- Public Decryption: Decrypt values publicly on-chain
- Automatic Signature Caching: No repeated wallet prompts
Application Layer (React, Vue, Vanilla JS, Node.js, Next.js)
β
Framework Adapters (Hooks, Composables, Promises)
β
Core SDK (Framework-Agnostic)
β’ FHEVMClient Manager
β’ Encryption Builder
β’ Decryption Manager
β’ Storage Abstraction
β
Zama FHEVM Infrastructure (Relayer SDK, Mock Utils)
- Separation of Concerns: Core logic is 100% framework-agnostic
- Adapter Pattern: Framework-specific code in thin adapters
- Wagmi-like DX: Familiar API for web3 developers
- Type Safety: Full TypeScript coverage
- Modularity: Import only what you need
cd packages/fhevm-sdk
pnpm buildpnpm sdk:watch# Blockchain
pnpm chain # Start local Hardhat node
pnpm deploy:localhost # Deploy contracts to localhost
pnpm deploy:sepolia # Deploy to Sepolia testnet
# Frontend Examples
pnpm start:react # Start React frontend
pnpm start:vue # Start Vue frontend
pnpm start:vanilla # Start Vanilla JS frontend
pnpm start:nodejs # Start Node.js server
pnpm start:nextjs # Start Next.js frontend
# SDK Development
pnpm sdk:build # Build SDK
pnpm sdk:watch # Watch mode (auto-rebuild)
pnpm sdk:test # Run SDK testsThis project is licensed under the BSD-3-Clause-Clear License. See LICENSE for details.
- π SDK Documentation: packages/fhevm-sdk/README.md
- π Zama Docs: https://docs.zama.ai/protocol/
- π¬ Discord: https://discord.com/invite/zama
Powered by Zama FHEVM