A minimal React frontend template for building FHEVM-enabled decentralized applications (dApps). This template provides a simple development interface for interacting with FHEVM smart contracts, specifically the FHECounter.sol
contract.
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: Works on both Sepolia testnet and local Hardhat node
- π¦ Monorepo Structure: Organized packages for SDK, contracts, and frontend
Before you begin, ensure you have:
- Node.js (v18 or higher)
- pnpm package manager
- MetaMask browser extension
- Git for cloning the repository
# 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 install
Set up your Hardhat environment variables by following the FHEVM documentation:
MNEMONIC
: Your wallet mnemonic phraseINFURA_API_KEY
: Your Infura API key for Sepolia
Option A: Local Development (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 to localhost
pnpm deploy:localhost
# Terminal 3: Start the frontend
pnpm start
Option B: Sepolia Testnet
# Deploy to Sepolia testnet
pnpm deploy:sepolia
# Start the frontend
pnpm start
- Open http://localhost:3000 in your browser
- Click "Connect Wallet" and select MetaMask
- If using localhost, add the Hardhat network to MetaMask:
- Network Name: Hardhat Local
- RPC URL:
http://127.0.0.1:8545
- Chain ID:
31337
- Currency Symbol:
ETH
- In production,
NEXT_PUBLIC_ALCHEMY_API_KEY
must be set (seepackages/nextjs/scaffold.config.ts
). The app throws if missing. - Ensure
packages/nextjs/contracts/deployedContracts.ts
points to your live contract addresses. - Optional: set
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID
for better WalletConnect reliability. - Optional: add per-chain RPCs via
rpcOverrides
inpackages/nextjs/scaffold.config.ts
.
When developing with MetaMask and Hardhat, you may encounter these common issues:
Problem: MetaMask tracks transaction nonces, but when you restart Hardhat, the node resets while MetaMask doesn't update its tracking.
Solution:
- Open MetaMask extension
- Select the Hardhat network
- Go to Settings β Advanced
- Click "Clear Activity Tab" (red button)
- This resets MetaMask's nonce tracking
Problem: MetaMask caches smart contract view function results. After restarting Hardhat, you may see outdated data.
Solution:
- Restart your entire browser (not just refresh the page)
- MetaMask's cache is stored in extension memory and requires a full browser restart to clear
π‘ Pro Tip: Always restart your browser after restarting Hardhat to avoid cache issues.
For more details, see the MetaMask development guide.
This template uses a monorepo structure with three main packages:
fhevm-react-template/
βββ packages/
β βββ fhevm-hardhat-template/ # Smart contracts & deployment
β βββ fhevm-sdk/ # FHEVM SDK package
β βββ nextjs/ # React frontend application
βββ scripts/ # Build and deployment scripts
useFHECounterWagmi.tsx
: Example hook demonstrating FHEVM contract interaction- Essential hooks for FHEVM-enabled smart contract communication
- Easily copyable to any FHEVM + React project
- MetaMask wallet provider hooks
- Compatible with EIP-6963 standard
- Easily adaptable for other wallet providers
- Replace
ethers.js
withWagmi
or other React-friendly libraries - Modular architecture for easy customization
- Support for multiple wallet providers
- 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.