A framework-agnostic toolkit that helps developers build confidential dApps with ease. Built with a modular adapter architecture that works seamlessly across React, Next.js, Vue, and Node.js environments.
Watch the Universal FHEVM SDK in action! See live demos of all showcases and learn how to use the adapters in your projects.
π Watch on YouTube
All examples are running with real FHEVM interactions on Sepolia testnet:
React Showcase: https://react-showcase-1738.up.railway.app/
Next.js Showcase: https://nextjs-showcase-1661.up.railway.app/
Vue Showcase: https://vue-showcase-2780.up.railway.app/
Node.js Showcase: packages/node-showcase/
Contract Details (FHEVM 0.9.0):
- FHE Counter Contract:
0x1b45fa7b7766fb27A36fBB0cfb02ea904214Cc75 - Ratings Contract:
0x0382053b0eae2A4A45C4A668505E2030913f559e - Voting Contract:
0x4D15cA56c8414CF1bEF42B63B0525aFc3751D2d1 - Network: Sepolia testnet (Chain ID: 11155111)
- FHEVM Version: 0.9.0
- Relayer SDK: 0.3.0-5
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Universal FHEVM SDK β
β packages/fhevm-sdk/ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β β β
βββββββΌββββββ βββββββββΌββββββββ βββββββββΌββββββββ
β CORE β β ADAPTERS β β SHOWCASES β
βsrc/core/ β βsrc/adapters/ β β packages/ β
βββββββ¬ββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β
βββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β ββββββββββββ ββββββββββββ ββββββββββββ β
β βfhevm.ts β βcontracts.β βindex.ts β β
β β β βts β β(exports) β β
β β-initializeβ β β ββββββββββββ β
β β-createEncβ β-FhevmCon β β
β β-decrypt β βtract β β
β β-publicDecβ ββββββββββββ β
β β-test/ β β
β ββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββ
β β
βββββββΌββββββ βββββββΌββββββ βββββββΌββββββ
β react.ts β β vue.ts β β node.ts β
β β β β β β
βuseWallet β βuseWalletVueβ βFhevmNode β
βuseFhevm β βuseFhevmVue β β(class) β
βuseContractβ βuseContract β βββββββββββββ
βuseEncrypt β βuseEncrypt β
βuseDecrypt β βuseDecrypt β
βuseFhevmOpsβ βuseFhevmOps β
βββββββββββββ βββββββββββββ
βββββββββββββββββββββββββββββββββββββββββ
β β
βββββββΌββββββββββ βββββββΌββββββββββ βββββββΌββββββββββ
βreact-showcase β βnextjs-showcase β β vue-showcase β
β β β β β β
βApp.tsx β βpage.tsx β βApp.vue β
βFheCounter β βcomponents/ β βcomponents/ β
βFheRatings β βFHECounter β βFHECounter β
βFheVoting β βFHERatings β βFHERatings β
β β βSimpleVoting β βSimpleVoting β
β β βtest/ β βtest/ β
βββββββββββββββββ ββββββββββββββββββ βββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββ
β node-showcase β
β β
β index.ts server.ts explorer.ts β
β counter.ts voting.ts ratings.ts β
β β
βββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β react-showcase β β vue-showcase β β node-showcase β
β β β β β β
β App.tsx β β App.vue β β index.ts β
β FheCounter.tsx β β FheCounter.vue β β counter.ts β
β FheRatings.tsx β β FheRatings.vue β β voting.ts β
β FheVoting.tsx β β FheVoting.vue β β ratings.ts β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
β import { useWallet, β import { useWalletVue,β import { FhevmNode
β useFhevm, β useFhevmVue } β } from
β useEncrypt, β } from β '@fhevm-sdk'
β useDecrypt } β '@fhevm-sdk' β
β from '@fhevm-sdk' β β
β β β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β @fhevm-sdk/src/ β
β β
β βββββββββββββββββββββββ β
β β adapters/react.ts β β
β β adapters/vue.ts β β
β β adapters/node.ts β β
β ββββββββββββ¬βββββββββββ β
β β β
β ββββββββββββΌβββββββββββ β
β β core/index.ts β β
β β core/fhevm.ts β β
β β core/contracts.ts β β
β ββββββββββββ¬βββββββββββ β
ββββββββββββββββΌβββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β Zama Relayer SDK β
β (@zama-fhe/relayer-sdk) β
β β
β ββββββββββββββββββββββββ β
β β createInstance() β β
β β createEncryptedInput β β
β β decryptValue() β β
β β publicDecrypt() β β
β ββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββ
fhevm-react-template/
βββ packages/
β βββ fhevm-sdk/ # Universal FHEVM SDK Core
β β βββ src/
β β β βββ core/ # Core FHEVM functionality
β β β β βββ fhevm.ts # FHEVM client initialization
β β β β βββ encryption.ts # Encryption operations
β β β β βββ decryption.ts # Decryption operations
β β β βββ adapters/ # Framework-specific adapters
β β β βββ react.ts # React hooks (re-exports)
β β β βββ useWallet.ts # Wallet connection hook
β β β βββ useFhevm.ts # FHEVM instance hook
β β β βββ useContract.ts # Contract interaction hook
β β β βββ useEncrypt.ts # Encryption hook
β β β βββ useDecrypt.ts # Decryption hook
β β β βββ useFhevmOperations.ts # Combined operations hook
β β β βββ vue.ts # Vue composables
β β β βββ node.ts # Node.js class adapter
β β βββ dist/ # Built output
β β
β βββ react-showcase/ # React Example
β β βββ src/
β β β βββ App.tsx # Main app (uses adapters)
β β β βββ components/
β β β βββ FheCounter.tsx # Uses useEncrypt, useDecrypt
β β β βββ FheRatings.tsx # Uses useEncrypt, useDecrypt
β β β βββ FheVoting.tsx # Uses useEncrypt
β β
β βββ nextjs-showcase/ # Next.js Example
β β βββ app/
β β β βββ page.tsx # Main page (uses adapters)
β β βββ components/ # Same as React showcase
β β
β βββ vue-showcase/ # Vue Example
β β βββ src/
β β β βββ App.vue # Main app (uses composables)
β β β βββ components/
β β β βββ FheCounter.vue # Uses useEncryptVue, useDecryptVue
β β β βββ FheRatings.vue # Uses useEncryptVue, useDecryptVue
β β β βββ FheVoting.vue # Uses useEncryptVue
β β
β βββ node-showcase/ # Node.js Example
β β βββ src/
β β β βββ index.ts # Main entry (uses FhevmNode)
β β β βββ counter.ts # Counter demo
β β β βββ voting.ts # Voting demo
β β β βββ ratings.ts # Ratings demo
β β
β βββ hardhat/ # Smart Contracts
β βββ contracts/ # Solidity contracts
β βββ deploy/ # Deployment scripts
β
βββ pnpm-workspace.yaml # Monorepo configuration
βββ README.md # This file
The Universal FHEVM SDK uses a clean adapter architecture where:
- Core provides framework-agnostic FHEVM operations
- Adapters wrap core functionality in framework-specific APIs
- Showcases demonstrate real-world usage with adapters
Hooks-based API - Similar to Wagmi pattern:
import { useWallet, useFhevm, useEncrypt, useDecrypt, useContract } from '@fhevm-sdk';
function MyComponent() {
// Wallet connection
const { address, isConnected, chainId, connect, disconnect } = useWallet();
// FHEVM instance
const { status, initialize, isInitialized } = useFhevm();
// Contract interaction
const { contract, isReady } = useContract(contractAddress, abi);
// Encryption
const { encrypt, isEncrypting, error: encryptError } = useEncrypt();
// Decryption (FHEVM 0.9.0)
const { decrypt, publicDecrypt, decryptMultiple, isDecrypting, error: decryptError } = useDecrypt();
// Usage example
const handleIncrement = async () => {
const encrypted = await encrypt(contractAddress, address, 1);
await contract.increment(encrypted.encryptedData, encrypted.proof);
};
// Self-relaying decryption example (for voting)
const handleTallyReveal = async (sessionId) => {
const tx = await contract.requestTallyReveal(sessionId);
const receipt = await tx.wait();
const event = receipt.logs.find(log => {
const parsed = contract.interface.parseLog(log);
return parsed?.name === 'TallyRevealRequested';
});
const { yesVotesHandle, noVotesHandle } = contract.interface.parseLog(event).args;
const { cleartexts, decryptionProof, values } = await decryptMultiple(
contractAddress,
signer,
[yesVotesHandle, noVotesHandle]
);
await contract.resolveTallyCallback(sessionId, cleartexts, decryptionProof);
};
return (
<div>
{!isConnected && <button onClick={connect}>Connect Wallet</button>}
{isConnected && <button onClick={handleIncrement}>Increment</button>}
</div>
);
}Composables-based API - Vue 3 Composition API:
<script setup lang="ts">
import { useWalletVue, useFhevmVue, useEncryptVue, useDecryptVue } from '@fhevm-sdk';
// Wallet connection
const { address, isConnected, chainId, connect, disconnect } = useWalletVue();
// FHEVM instance
const { status, initialize, isInitialized } = useFhevmVue();
// Encryption
const { encrypt, isEncrypting, error: encryptError } = useEncryptVue();
// Decryption (FHEVM 0.9.0)
const { decrypt, publicDecrypt, decryptMultiple, isDecrypting, error: decryptError } = useDecryptVue();
// Usage example
const handleIncrement = async () => {
const encrypted = await encrypt.value(contractAddress, address.value, 1);
await contract.increment(encrypted.encryptedData, encrypted.proof);
};
</script>
<template>
<div>
<button v-if="!isConnected" @click="connect">Connect Wallet</button>
<button v-if="isConnected" @click="handleIncrement">Increment</button>
</div>
</template>Class-based API - For server-side operations:
import { FhevmNode } from '@fhevm-sdk';
const fhevm = new FhevmNode({
rpcUrl: 'https://sepolia.infura.io/v3/YOUR_KEY',
privateKey: 'YOUR_PRIVATE_KEY',
chainId: 11155111
});
await fhevm.initialize();
// Encrypt
const encrypted = await fhevm.encrypt(contractAddress, walletAddress, 1);
// Decrypt
const decrypted = await fhevm.decrypt(handle, contractAddress);
// Public decrypt
const publicDecrypted = await fhevm.publicDecrypt(handle);
// Execute transaction
const contract = fhevm.createContract(contractAddress, abi);
await fhevm.executeEncryptedTransaction(contract, 'increment', encrypted);Create a new FHEVM project instantly:
# React
npx create-fhevm-react my-app
cd my-app
npm install && npm start
# Next.js
npx create-fhevm-nextjs my-app
cd my-app
npm install && npm run dev
# Vue
npx create-fhevm-vue my-app
cd my-app
npm install && npm run devClone and run the full development environment:
# 1. Clone repository
git clone https://github.com/your-username/fhevm-react-template.git
cd fhevm-react-template
# 2. Install dependencies
pnpm install
# 3. Build SDK
pnpm sdk:build
# 4. Run showcase
pnpm --filter react-showcase start # React on :3000
pnpm --filter nextjs-showcase dev # Next.js on :3001
pnpm --filter vue-showcase dev # Vue on :3003
pnpm --filter node-showcase explorer # Interactive CLI mode (recommended)
pnpm --filter node-showcase start # HTTP server mode
pnpm --filter node-showcase cli # Non-interactive CLI mode
Run the following only in the node-showcase dir as an HTTP server with API endpoints:
# Start the HTTP server
pnpm start
# Server runs on http://localhost:3001
# Available endpoints:
# - GET / - List available endpoints
# - GET /health - Health check
# - GET /config - Get FHEVM configuration
# - POST /counter - Run counter demo
# - POST /voting - Run voting demo
# - POST /ratings - Run ratings demo
# - POST /run-all - Run all demosTest endpoints using PowerShell:
# Run counter demo
Invoke-RestMethod -Uri http://localhost:3001/counter -Method POST
# Run voting demo
Invoke-RestMethod -Uri http://localhost:3001/voting -Method POST
# Get configuration
Invoke-RestMethod -Uri http://localhost:3001/config -Method GETRun all demos sequentially without interaction:
# Run all demos at once
pnpm cli
# Output includes:
# - Counter demo: Increment β Decrement β Decrypt
# - Voting demo: Create session β Vote
# - Ratings demo: Submit rating β Public decrypt stats# Interactive CLI mode (recommended for testing)
pnpm explorer
# HTTP server mode
pnpm start
# Non-interactive CLI mode
pnpm cli
# Development mode (watch HTTP server)
pnpm dev
# Build TypeScript
pnpm buildThe FHEVM Explorer is an interactive CLI wizard that provides a guided, user-friendly way to explore the Universal FHEVM SDK capabilities. It's the recommended way to experience FHEVM demos step-by-step.
The Explorer offers a beautiful, context-aware interface that guides you through FHEVM operations:
- π Interactive Menu - Navigate through different demo options with arrow keys
- π’ Counter Demo - Experience increment/decrement operations with encrypted values
- Interactive prompts for increment/decrement amounts
- Real-time transaction feedback
- Decryption results display
- π³οΈ Voting Demo - Explore encrypted voting systems
- Create voting sessions or use existing ones
- Choose votes (Yes/No) with encryption
- View encrypted results after voting
- β Ratings Demo - Submit encrypted ratings and reviews
- Create review cards
- Submit encrypted ratings with user input
- View public decrypted statistics
- π Test Mode - Verify your setup before running demos
- Check environment variables configuration
- Verify network connection
- Test wallet setup
- Validate FHEVM client initialization
- Verify contract accessibility
- π― Run All Demos - Execute all demos sequentially in one session
- π Session Summary - Track all completed demos with timestamps and results
- Beautiful UI - Color-coded output with loading spinners and progress indicators
- Guided Experience - Step-by-step prompts that walk you through each operation
- Real Transactions - All demos use actual blockchain transactions on Sepolia testnet
- Error Handling - Helpful error messages and recovery suggestions
- Session Tracking - Keep track of all demos you've completed with detailed summaries
π Welcome to FHEVM Explorer!
Universal FHEVM SDK - Interactive Demo Experience
Explore the world of confidential computing on blockchain
Experience encrypted operations with guided demos
β
FHEVM environment ready!
Wallet: 0xb8c81a641A4A4C47d11e5464C77EdcB9737784CC
Balance: 0.042681970725989092 ETH
Network: Sepolia (11155111)
? Choose your FHEVM demo:
β― π’ Counter Demo - Increment/Decrement Operations
π³οΈ Voting Demo - Encrypted Voting System
β Ratings Demo - Review Cards with Encrypted Ratings
π Test Mode - Verify Setup Only
π― Run All Demos
β Exit Explorer
# Navigate to node-showcase
cd packages/node-showcase
# Start the interactive explorer
pnpm explorerThe Explorer will:
- Initialize your FHEVM environment and verify configuration
- Display an interactive menu with all available demos
- Guide you through each demo with prompts and feedback
- Show real-time transaction status and results
- Track your session and provide a summary at the end
This is the perfect tool for developers learning FHEVM or demonstrating the SDK's capabilities to others! <<<<<<< Updated upstream
=======
Stashed changes
Each showcase demonstrates real-world adapter usage:
- React Showcase - React hooks usage
- Next.js Showcase - Next.js with React hooks
- Vue Showcase - Vue composables usage
- Node.js Showcase - Server-side operations
- π Interactive CLI Mode - Guided wizard with prompts (
pnpm explorer) - π HTTP Server Mode - REST API with endpoints (
pnpm start) - π Non-Interactive CLI Mode - Sequential execution (
pnpm cli)
- π Interactive CLI Mode - Guided wizard with prompts (
All showcases include comprehensive FHEVM contract tests in their respective test/ directories:
packages/react-showcase/test/- React showcase testspackages/nextjs-showcase/test/- Next.js showcase testspackages/vue-showcase/test/- Vue showcase tests
Each test directory contains:
FHECounter.test.js- Counter contract tests (increment, decrement, edge cases)FHERatings.test.js- Ratings contract tests (card creation, encrypted ratings, public decryption)SimpleVoting.test.js- Voting contract tests (session creation, encrypted voting, tally reveal)
# Run all showcase tests
pnpm test:showcases
# Run tests for a specific showcase
pnpm test:react # React showcase tests
pnpm test:nextjs # Next.js showcase tests
pnpm test:vue # Vue showcase tests
# Run from a specific showcase directory
cd packages/react-showcase && pnpm test
cd packages/nextjs-showcase && pnpm test
cd packages/vue-showcase && pnpm test
# Run Hardhat tests (includes all showcase tests)
pnpm hardhat:testTests run in Hardhat's FHEVM mock environment, allowing fast local testing without a live network.
- Single core implementation used by all adapters
- No framework-specific dependencies in core
- Easy to extend with new adapters
- Familiar patterns for web3 developers
- Hooks-based (React) and composables-based (Vue)
- Clean, intuitive interface
- Full type safety across all adapters
- Excellent IDE support
- Comprehensive type definitions
- EIP-712 signature-based decryption
- Public decryption support
- Self-relaying decryption pattern (event-driven)
- Multiple handle decryption (
decryptMultiple) - Encrypted transaction execution
- No mocks - all real blockchain interactions
- Counter Demo: Increment/decrement with EIP-712 user decryption
- Ratings Demo: Encrypted ratings with public decryption
- Voting Demo: Encrypted voting with self-relaying decryption (event-driven tally reveal)
import { useWallet, useFhevm, useEncrypt, useDecrypt } from '@fhevm-sdk';
export default function FheCounter() {
const { address, isConnected, connect } = useWallet();
const { status, initialize } = useFhevm();
const { encrypt } = useEncrypt();
const { decrypt } = useDecrypt();
useEffect(() => {
if (isConnected && status === 'idle') {
initialize();
}
}, [isConnected, status, initialize]);
const handleIncrement = async () => {
const encrypted = await encrypt(contractAddress, address, 1);
// Execute transaction...
};
return <div>...</div>;
}<script setup lang="ts">
import { useWalletVue, useFhevmVue, useEncryptVue } from '@fhevm-sdk';
const { address, isConnected, connect } = useWalletVue();
const { status, initialize } = useFhevmVue();
const { encrypt } = useEncryptVue();
watch(() => isConnected.value, (newVal) => {
if (newVal && status.value === 'idle') {
initialize();
}
});
</script>
<template>
<div>...</div>
</template>import { FhevmNode } from '@fhevm-sdk';
async function main() {
const fhevm = new FhevmNode({ rpcUrl, privateKey, chainId });
await fhevm.initialize();
const encrypted = await fhevm.encrypt(contractAddress, walletAddress, 1);
const contract = fhevm.createContract(contractAddress, abi);
await fhevm.executeEncryptedTransaction(contract, 'increment', encrypted);
}- Node.js 18+
- pnpm (recommended) or npm
- MetaMask (for frontend examples)
- Sepolia ETH (for transactions)
MIT License - see LICENSE file for details
Contributions are welcome! Please see our contributing guidelines for more information.
Built with Privacy for the Zama Universal FHEVM SDK Bounty