A framework-agnostic frontend toolkit that helps developers run confidential dApps with ease.
Try the SDK in action on Sepolia testnet:
π Note: Live demos require:
- MetaMask or compatible Web3 wallet
- Sepolia testnet ETH (Get from faucet)
- Connect wallet to Sepolia network (Chain ID: 11155111)
π» Backend Examples: Node.js backend and automation examples are designed for local/server deployment. See Examples Guide for setup instructions.
FHEVM (Fully Homomorphic Encryption Virtual Machine) enables computation on encrypted data directly on Ethereum. This template demonstrates how to build dApps that can perform computations while keeping data private.
- π FHEVM Integration: Built-in support for fully homomorphic encryption
- βοΈ React + Next.js: Modern, performant frontend framework
- π¨ Tailwind CSS: Utility-first styling for rapid UI development
- π RainbowKit: Seamless wallet connection and management
- π Multi-Network Support: Auto-detects localhost and Sepolia networks
- π¦ Monorepo Structure: Organized packages for SDK, contracts, and frontend
- π Auto-Generated Contracts: Type-safe contract ABIs via
pnpm generate
Before you begin, ensure you have:
- Node.js (v20 or higher)
- pnpm package manager
- MetaMask browser extension
- Git for cloning the repository
This template uses a monorepo structure with three main packages:
fhevm-universal-sdk/
βββ packages/
β βββ fhevm-sdk/ # Core universal FHEVM SDK
β β βββ docs/ # Internal SDK documentation (debug, migration, validation, etc.)
β β βββ src/ # SDK source code
β β β βββ core/ # Core FHE logic (init, encryption, decryption)
β β β βββ internal/ # Internal helpers not exposed publicly
β β β βββ react/ # React hooks & adapters
β β β βββ storage/ # Encrypted local/session storage utilities
β β β βββ types/ # TypeScript definitions
β β β βββ utils/ # General-purpose utilities
β β β βββ vanilla/ # Adapter for Vanilla JS
β β β βββ vue/ # Adapter for Vue
β β βββ test/ # Unit & integration tests for all modules
β βββ hardhat/ # Hardhat environment for contract dev & testing
β βββ nextjs/ # Next.js (React) showcase application
βββ examples/ # Cross-framework integration examples
β βββ vanilla-js/ # Plain browser example using SDK
β βββ vue-app/ # Vue 3 + Vite example
β βββ nodejs-backend/ # Express backend using SDK
β βββ nodejs-automation/ # Node.js automation & job scheduling
βββ scripts/ # Global build & deploy utilities
β βββ generateTsAbis.ts # Generates TS typings from Solidity ABIs
βββ README.md # Project documentation
βββ package.json # Root dependency manager
βββ pnpm-workspace.yaml # Workspace definition for monorepo
# Clone the repository
git clone <repository-url>
cd fhevm-react-template
# Initialize submodules (includes fhevm-hardhat-template)
git submodule update --init --recursive
# Install dependencies
pnpm installSetup Hardhat variables (required for both localhost and Sepolia):
cd packages/hardhat
# Set your wallet mnemonic
npx hardhat vars set MNEMONIC
# Example: "test test test test test test test test test test test junk"
# Set Infura API key (required for Sepolia, optional for localhost)
npx hardhat vars set INFURA_API_KEY
# Example: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"π§© Localhost (Recommended for Testing)
# Terminal 1: Start local Hardhat node
pnpm chain
# RPC URL: http://127.0.0.1:8545 | Chain ID: 31337
# Terminal 2: Deploy contracts
pnpm deploy:localhost
# Terminal 3: Start frontend
pnpm startπ Sepolia Testnet
# Deploy to Sepolia
pnpm deploy:sepolia
# Start frontend
pnpm startProduction Notes:
- Set
NEXT_PUBLIC_ALCHEMY_API_KEYinpackages/nextjs/scaffold.config.ts - Verify contract addresses in
packages/nextjs/contracts/deployedContracts.ts - Optional: Set
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_IDfor WalletConnect
π‘ Auto-Detection: The app automatically detects your network and uses the correct contracts!
- Open http://localhost:3000
- Click "Connect Wallet" and select MetaMask
- For localhost: Add Hardhat network to MetaMask:
- Network Name:
Hardhat Local - RPC URL:
http://127.0.0.1:8545 - Chain ID:
31337 - Currency Symbol:
ETH
- Network Name:
This template includes comprehensive examples showing how to use the FHEVM SDK across different frameworks and environments:
- Vanilla JS (
examples/vanilla-js/) - Pure JavaScript with Vite - Vue 3 (
examples/vue-app/) - Vue 3 with Composition API
- Express.js (
examples/nodejs-backend/) - REST API backend with Node.js - Automation (
examples/nodejs-automation/) - Scheduled tasks and batch processing
All examples use the same @fhevm-sdk/core - what differs is the framework context.
See Examples Guide for:
- Detailed overview of each example
- SDK usage patterns by framework
- Comparison table
- Configuration options
Quick start:
# Browser - Vanilla JS
pnpm vanilla:dev
# Browser - Vue 3
pnpm vue:dev
# Backend - Express API
cp examples/nodejs-backend/.env.example examples/nodejs-backend/.env && pnpm backend:dev
# Automation - Scheduled tasks
cp examples/nodejs-automation/.env.example examples/nodejs-automation/.env && pnpm automation:start help
pnpm automation:task:batch # Automation - Batch Encrypt
pnpm automation:task:decrypt # Automation - Daily DecryptAfter deploying contracts, run pnpm generate to auto-generate type-safe ABIs for Next.js, Vue, and Vanilla JS. This keeps your frontend and contracts perfectly in sync!
The SDK uses IndexedDB by default to persist FHEVM decryption signatures (no re-signing after page refresh). Automatic fallback to localStorage or in-memory storage if unavailable.
// Default: IndexedDB (persistent)
import { useIndexedDBStorage } from "~/hooks/helper/useIndexedDBStorage";
const { storage } = useIndexedDBStorage({ dbName: "fhevm-app", storeName: "signatures" });
// Alternative: In-memory (non-persistent, faster)
import { useInMemoryStorage } from "@fhevm-sdk";
const { storage } = useInMemoryStorage();Nonce Mismatch: After restarting Hardhat, clear MetaMask activity:
- Settings β Advanced β "Clear Activity Tab"
Cached Data: Restart your browser completely (not just refresh) to clear MetaMask's cache.
π‘ See MetaMask dev guide for details.
- FHEVM Documentation - Complete FHEVM guide
- FHEVM Hardhat Guide - Hardhat integration
- Relayer SDK Documentation - SDK reference
- Environment Setup - MNEMONIC & API keys
- MetaMask + Hardhat Setup - Local development
- React Documentation - React framework guide
- FHEVM Discord - Community support
- GitHub Issues - Bug reports & feature requests
This project is licensed under the BSD-3-Clause-Clear License. See the LICENSE file for details.