The complete toolkit for building confidential dApps with FHEVM
A universal, framework-agnostic SDK that provides everything you need to build confidential applications with fully homomorphic encryption on any blockchain
One SDK. All Frameworks. Zero Config.
- Universal SDK - Works in React, Vue, Node.js, and vanilla JS
- Wagmi-like API - Intuitive, modular interface familiar to Web3 developers
- EIP-712 Signing - Secure user decryption with wallet signatures
- Multi-Environment - Next.js, Vue, and Node.js examples
- Zero Config - Works out of the box with sensible defaults
- Interactive Wizard - Guided setup and testing experience
- Comprehensive CLI - Command-line interface for all operations
- Mock Mode - Auto-detection for easy development (no Windows API issues)
- TypeScript First - Full type safety and IntelliSense
- Cross-Framework - Data encrypted in one framework works in another
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Universal FHEVM SDK β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β CORE β β REACT β β VUE β β
β β β β β β β β
β β β’ FHEVMClientβ β β’ useFHEVM β β β’ useFHEVM β β
β β β’ Encryptionβ β β’ useEncryptβ β β’ useEncryptβ β
β β β’ Decryptionβ β β’ useDecryptβ β β’ useDecryptβ β
β β β’ Storage β β β’ Componentsβ β β’ Composablesβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β NODE β β HARDHAT β β MOCK β β
β β β β β β β β
β β β’ CLI Tools β β β’ Detection β β β’ Testing β β
β β β’ Utilities β β β’ Integrationβ β β’ Developmentβ β
β β β’ Batch Ops β β β’ Local Dev β β β’ No RPC β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β REACT β β VUE β β NODE β
β β β β β β
β useFHEVM() β β useFHEVM() β β CLI Tools β
β useEncrypt()β β useEncrypt()β β Utilities β
β useDecrypt()β β useDecrypt()β β Batch Ops β
ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ
β β β
ββββββββββββββββββββΌβββββββββββββββββββ
β
ββββββββΌβββββββ
β CORE β
β β
β FHEVMClient β
β Encryption β
β Decryption β
β Storage β
ββββββββ¬βββββββ
β
ββββββββΌβββββββ
β ZAMA β
β β
β Relayer SDK β
β FHEVM Types β
β Mock Inst. β
βββββββββββββββ
# Clone the repository
git clone https://github.com/0xNana/fhevm-react-template.git
cd fhevm-react-template
# Install dependencies
pnpm install
# Quick setup (configures everything)
pnpm quickstart# Frontend Examples
pnpm dev # Next.js example
pnpm vue:dev # Vue example
# Interactive Experience
pnpm fhevm:wizard # π§ββοΈ Interactive FHEVM Wizard
# Demo Operations
pnpm demo:counter # Counter operations
pnpm demo:bank # Bank operations
pnpm demo:voting # Voting operations
# See all examples
pnpm examplesβββββββββββββββ βββββββββββββββ βββββββββββββββ
β REACT β β CORE β β ZAMA β
β β β β β β
β useFHEVM() βββββΆβ FHEVMClient βββββΆβ Relayer SDK β
β useEncrypt()β β encrypt() β β FHEVM Types β
β useDecrypt()β β decrypt() β β Mock Inst. β
β Components β β Storage β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β VUE β β CORE β β ZAMA β
β β β β β β
β useFHEVM() βββββΆβ FHEVMClient βββββΆβ Relayer SDK β
β useEncrypt()β β encrypt() β β FHEVM Types β
β useDecrypt()β β decrypt() β β Mock Inst. β
β Composables β β Storage β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β NODE β β CORE β β ZAMA β
β β β β β β
β CLI Tools βββββΆβ FHEVMClient βββββΆβ Relayer SDK β
β Utilities β β encrypt() β β FHEVM Types β
β Batch Ops β β decrypt() β β Mock Inst. β
β Server β β Storage β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
- Next.js Demo: https://next.0xelegant.dev
- Vue Demo: https://vue.0xelegant.dev
Note: Deployment links have been updated xD. All examples work locally with
pnpm dev,pnpm vue:dev, andpnpm cli:start.
# Install the SDK
npm install @fhevm/sdk
# Or with pnpm
pnpm add @fhevm/sdkimport { createFHEVMClient } from '@fhevm/sdk'
// Create client
const client = createFHEVMClient({
rpcUrl: 'https://sepolia.infura.io/v3/INPUT_YOUR_INFURA_API_KEY_HERE',
chainId: 11155111
})
// Initialize
await client.initialize()
// Encrypt
const encrypted = await client.encrypt(42, {
publicKey: '0x...'
})
// Decrypt (public)
const decrypted = await client.decrypt({
handle: encrypted,
contractAddress: '0x...',
usePublicDecrypt: true
})import { useFHEVM, useEncrypt, useDecrypt } from '@fhevm/sdk/react'
function MyComponent() {
const { instance, isReady } = useFHEVM()
const { encrypt, isEncrypting } = useEncrypt(instance, {
publicKey: '0x...',
contractAddress: '0x...'
})
const { decrypt, isDecrypting } = useDecrypt(instance, {
handle: '0x...',
contractAddress: '0x...'
})
return (
<div>
<button onClick={() => encrypt(42)} disabled={isEncrypting}>
Encrypt
</button>
<button onClick={() => decrypt()} disabled={isDecrypting}>
Decrypt
</button>
</div>
)
}<script setup>
import { useFHEVM, useEncryption, useDecryption } from '@fhevm/sdk/vue'
const { instance, isReady } = useFHEVM()
const { encrypt, isEncrypting } = useEncryption(instance, {
publicKey: '0x...',
contractAddress: '0x...'
})
const { decrypt, isDecrypting } = useDecryption(instance, {
handle: '0x...',
contractAddress: '0x...'
})
</script>import { createFHEVMClientForNode, encryptValue, decryptValue } from '@fhevm/sdk/node'
// Create client (auto-detects mock mode)
const client = createFHEVMClientForNode({
rpcUrl: 'http://localhost:8545', // Mock mode default
chainId: 31337
})
// Initialize
await client.initialize()
// Encrypt value
const encrypted = await encryptValue(42, '0x...', client)
// Decrypt handle
const decrypted = await decryptValue(
'0x...', // handle
'0x...', // contract address
client,
{ usePublicDecrypt: true }
)import { createFHEVMClientForNode } from '@fhevm/sdk/node'
import { ethers } from 'ethers'
// Server-side FHEVM operations
const client = createFHEVMClientForNode({
rpcUrl: process.env.RPC_URL || 'http://localhost:8545',
chainId: parseInt(process.env.CHAIN_ID || '31337')
})
await client.initialize()
// Batch operations
const values = [1, 2, 3, 4, 5]
const encrypted = await Promise.all(
values.map(value => encryptValue(value, publicKey, client))
)
// Contract interaction
const contract = new ethers.Contract(address, abi, signer)
const result = await contract.someFunction(encrypted[0])# Interactive setup and testing
pnpm fhevm:wizard
# Choose from:
# - π¦ Bank Demo (deposit, withdraw, transfer)
# - π³οΈ Voting Demo (create session, vote, decrypt results)
# - π’ Counter Demo (increment, decrement, get count)
# - π§ͺ Test Mode (verify environment)# Initialize setup
pnpm fhevm-cli:init
# Basic operations
pnpm fhevm-cli:encrypt --value 5 --public-key 0x...
pnpm fhevm-cli:decrypt --handle 0x... --contract 0x... --public
# Batch operations
pnpm fhevm-cli:batch-encrypt --values "1,2,3" --public-key 0x...
pnpm fhevm-cli:batch-decrypt --handles "0x...,0x..." --contract 0x... --public
# User decryption (EIP-712)
pnpm fhevm-cli:user-decrypt --handle 0x... --contract 0x... --signature 0x...
# Status and testing
pnpm fhevm-cli:status --detailed
pnpm fhevm-cli:test# Counter operations
pnpm demo:counter # Increment, get count, decrypt
# Bank operations
pnpm demo:bank # Deposit, withdraw, transfer, decrypt
# Voting operations
pnpm demo:voting # Create session, vote, decrypt results
# Run all demos
pnpm demo:all# Quick setup
pnpm quickstart
# Frontend Development
pnpm dev # Next.js example
pnpm vue:dev # Vue example
# Interactive Experience
pnpm fhevm:wizard # π§ββοΈ Interactive FHEVM Wizard
# Demo Operations
pnpm demo:counter # Counter operations
pnpm demo:bank # Bank operations
pnpm demo:voting # Voting operations
pnpm demo:all # Run all demos
# Universal CLI
pnpm fhevm-cli:init # Interactive setup
pnpm fhevm-cli:encrypt # Encrypt values
pnpm fhevm-cli:decrypt # Decrypt handles
pnpm fhevm-cli:batch-encrypt # Batch encryption
pnpm fhevm-cli:batch-decrypt # Batch decryption
pnpm fhevm-cli:user-decrypt # User decryption (EIP-712)
pnpm fhevm-cli:status # Check status
pnpm fhevm-cli:test # Test operations
# Building
pnpm build:all # Build everything
pnpm sdk:build # Build SDK only
# Examples
pnpm examples # Show all examples# Next.js
pnpm next:dev # Development server
pnpm next:build # Build for production
pnpm next:start # Start production server
# Vue
pnpm vue:dev # Development server
pnpm vue:build # Build for production
pnpm vue:preview # Preview production build
## Architecture
packages/ βββ fhevm-sdk/ # Universal SDK β βββ src/ # Core functionality β βββ react/ # React hooks & components β βββ vue/ # Vue composables β βββ node/ # Node.js utilities & CLI βββ nextjs-example/ # Next.js showcase βββ vue-example/ # Vue showcase βββ node-example/ # Node.js demos & wizard β βββ src/fhevm-wizard.js # π§ββοΈ Interactive wizard β βββ src/server-side/ # Demo operations β βββ src/cli/ # CLI tools βββ hardhat/ # Smart contracts
### Key Components
- ** Interactive Wizard**: Guided setup and testing experience
- ** Mock Mode**: Auto-detection for easy development
- ** Universal SDK**: Framework-agnostic core
- ** Comprehensive CLI**: All FHEVM operations
- ** Cross-Framework**: Data compatibility across frameworks
## Encryption & Decryption
### Public Decryption (No Signature)
```typescript
const decrypted = await client.decrypt({
handle: encrypted,
contractAddress: '0x...',
usePublicDecrypt: true
})
import { FhevmDecryptionSignature } from '@fhevm/sdk'
// Generate signature
const signature = await FhevmDecryptionSignature.loadOrSign(
instance,
[contractAddress],
signer,
storage
)
// Decrypt with signature
const decrypted = await client.decrypt({
handle: encrypted,
contractAddress: '0x...',
signature: signature.signature
})import { FHEVMProvider, EncryptButton, DecryptButton } from '@fhevm/sdk/react'
<FHEVMProvider config={config}>
<EncryptButton
value={42}
publicKey="0x..."
onEncrypted={handleEncrypted}
/>
<DecryptButton
handle={encrypted}
usePublicDecrypt={true}
onDecrypted={handleDecrypted}
/>
</FHEVMProvider>- Next.js:
packages/nextjs-example/- Full React app with wagmi integration - Vue:
packages/vue-example/- Complete Vue 3 app with composables - Node.js:
packages/node-example/- CLI tools, wizard, and demos
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β UPSTREAM (Zama) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β BROWSER β β MOCK β β REACT β β
β β β β β β β β
β β β’ Relayer β β β’ Basic β β β’ Hooks β β
β β β’ EIP-712 β β β’ Testing β β β’ Componentsβ β
β β β’ Types β β β’ Local β β β’ Examples β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β OUR ENHANCEMENTS β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β CORE β β REACT β β VUE β β
β β β β β β β β
β β β’ Universal β β β’ Enhanced β β β’ Composablesβ β
β β β’ Cross-Env β β β’ Hooks β β β’ Vue 3 β β
β β β’ Storage β β β’ Componentsβ β β’ Pinia β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β NODE β β HARDHAT β β BATCH β β
β β β β β β β β
β β β’ CLI Tools β β β’ Detection β β β’ Encrypt β β
β β β’ Utilities β β β’ Integrationβ β β’ Decrypt β β
β β β’ Server β β β’ Local Dev β β β’ Efficiencyβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# π§ββοΈ Interactive Wizard (Recommended)
pnpm fhevm:wizard
# Choose from:
# - π¦ Bank Demo (deposit, withdraw, transfer)
# - π³οΈ Voting Demo (create session, vote, decrypt results)
# - π’ Counter Demo (increment, decrement, get count)
# - π§ͺ Test Mode (verify environment)# Frontend examples
pnpm next:dev # Next.js example
pnpm vue:dev # Vue example
# Demo operations
pnpm demo:counter # Counter operations
pnpm demo:bank # Bank operations
pnpm demo:voting # Voting operations
pnpm demo:all # Run all demos# Works without real blockchain (perfect for development)
pnpm fhevm-cli:init
# Choose "Mock Mode" for instant setup
# Test encryption/decryption
pnpm fhevm-cli:encrypt --value 42 --public-key 0x123
pnpm fhevm-cli:decrypt --handle 0x... --contract 0x456 --publicCreate a .env file in the root:
# Required
RPC_URL=https://sepolia.infura.io/v3/PLS_SER_INPUT_YOUR_INFURA_API_KEY_HERE
CHAIN_ID=11155111
# Optional
PRIVATE_KEY=0x... # For Node.js operations
MNEMONIC="..." # Alternative to PRIVATE_KEYconst config = {
rpcUrl: 'https://sepolia.infura.io/v3/PLS_SER_INPUT_YOUR_INFURA_API_KEY_HERE',
chainId: 11155111,
mockChains: {
31337: 'http://localhost:8545' // Local development
}
}- Clone repository:
git clone ... && cd fhevm-react-template - Install dependencies:
pnpm install - Quick setup:
pnpm quickstart - Try the wizard:
pnpm fhevm:wizard(recommended) - Or choose environment:
pnpm dev|pnpm vue:dev|pnpm demo:counter - Start building! π
- Interactive Wizard: Guided setup and testing
- Mock Mode: No Windows API headaches
- Zero Config: Works out of the box
- TypeScript First: Full type safety
- Cross-Framework: Data works everywhere
- Multiple Environments: React, Vue, Node.js
- Real Blockchain: Production-ready integration
- Comprehensive CLI: All operations available
- Error Handling: Robust error recovery
- **Security**: EIP-712 signatures, input validation
- **Performance**: Lazy loading, caching, optimization
- **Documentation**: Comprehensive guides and examples
## Contributing
This is part of the Universal FHEVM SDK. Contributions are welcome!
## License
BSD-3-Clause-Clear License
---
**Ready to build confidential dApps?** Run `pnpm quickstart` to get started!