Documentation Index
Fetch the complete documentation index at: https://mintlify.com/0xchriswilder/journey/llms.txt
Use this file to discover all available pages before exploring further.
Week 3: Full-Stack Confidential dApps
Subtitle: Build end-to-end encrypted applications with frontend integration Estimated Time: 12 hours of lessons + 8 hours homeworkObjectives
Frontend Integration
Integrate fhevmjs client SDK with a React frontend
Private Voting
Build a complete Private Voting dApp from scratch
Encrypted Inputs
Implement encrypted inputs, homomorphic tallying, and controlled decryption
Advanced Patterns
Handle access control, error handling, and production patterns
Milestone
Fully functional Private Voting dApp with React frontend
Deployed and tested on Sepolia testnet
Client-side encryption working correctly
Understanding of all three decryption patterns
Lessons
Lesson 3.1: Frontend Integration with fhevmjs
Duration: 60 minutesLearning Objectives
Learning Objectives
- Install and initialize fhevmjs in a React project
- Create an FHE client instance and initialize it with the network public key
- Encrypt user inputs in the browser using the SDK
- Send encrypted transactions using ethers.js + fhevmjs
Setting Up the Relayer SDK in React
Setting Up the Relayer SDK in React
The
@zama-fhe/relayer-sdk handles all FHE operations: initializing the FHEVM instance, encrypting user inputs, and decrypting on-chain values.The SDK is a singleton —
initFhevm() returns the cached instance after first call.React Component Integration
React Component Integration
Universal FHEVM SDK Reference
Universal FHEVM SDK Reference
For a full production implementation, study the Universal FHEVM SDK:Repository: 0xchriswilder/fhevm-react-templateLive Demos:Features:
- React hooks:
useWallet,useFhevm,useEncrypt,useDecrypt,useContract - Vue composables: Vue 3 Composition API equivalents
- Node.js adapter: Server-side operations, CLI explorer
- Working dApps: FHE Counter, Encrypted Ratings, SimpleVoting
All demos are deployed on Sepolia testnet with real contract interactions.
Lesson 3.2: FHEVM Relayer SDK Deep Dive
Duration: 75 minutesLearning Objectives
Learning Objectives
- Initialize the Relayer SDK in both browser and Node.js environments
- Implement all three decryption patterns: EIP-712 User Decrypt, Public Decrypt, and Self-Relaying Decrypt
- Build production React hooks (useEncrypt, useDecrypt, useFhevm)
- Write Hardhat deployment scripts for FHEVM contracts
- Understand the full lifecycle: encrypt → submit → compute → decrypt → verify
Three Decryption Patterns
Three Decryption Patterns
EIP-712 User Decrypt
For: User-private data (my balance)User signs an EIP-712 message to prove ownership, then decrypts their own value off-chain.
Public Decrypt
For: Shared data (ratings, public tallies)Anyone can request decryption of values marked as publicly decryptable.
Self-Relaying Decrypt
For: Revealed-after-deadline data (vote tallies, auction results)Contract marks values decryptable → client decrypts off-chain → submits proof on-chain for verification.
Lesson 3.3: Building the Private Voting dApp
Duration: 75 minutesLearning Objectives
Learning Objectives
- Understand the full voting flow: create session → vote → request reveal → resolve tally
- Implement encrypted vote casting with FHE.select() for homomorphic tallying
- Build the three-phase reveal: requestTallyReveal → publicDecrypt → resolveTallyCallback
- Handle edge cases: already voted, session expired, unauthorized reveal
Vote Casting Flow
Vote Casting Flow
What happens when a user clicks YES or NO:
Frontend encrypts
createEncryptedInput() → add32(1) for Yes or add32(0) for No → encrypt()Returns { handles, inputProof }On-chain processing
FHE.fromExternal()validates proofFHE.eq(v, yes)checks if vote is YESFHE.select()adds encrypted 1 to correct tally- Updates both yesVotes and noVotes
- Calls
FHE.allowThis()andFHE.allow(creator) - Sets
hasVoted[sessionId][msg.sender] = true
Encryption happens in the browser. Only the handle and proof go on-chain.
Session Creation and Reveal Flow
Session Creation and Reveal Flow
Create Session
- Frontend calls
contract.createSession(durationSeconds) - Contract pushes new Session with encrypted zero tallies
- Emits
SessionCreated(sessionId, creator, endTime) - Parse event from receipt to get sessionId and endTime for UI
- Only session creator calls
contract.requestTallyReveal(sessionId) - Contract sets
revealRequested = true - Calls
FHE.makePubliclyDecryptable()on yesVotes and noVotes - Emits
TallyRevealRequested(sessionId, yesHandle, noHandle)
- Listen for
TallyRevealRequestedevent - Extract yesHandle and noHandle from event logs
- Call
instance.publicDecrypt([yesHandle, noHandle]) - Returns plaintext counts + decryption proof
- Encode counts:
abi.encode(yesCount, noCount) - Call
contract.resolveTallyCallback(sessionId, cleartexts, proof) - Contract runs
FHE.checkSignatures()— reverts if invalid - Stores
revealedYesandrevealedNo - Sets
resolved = true - Anyone can read results via
getSession(sessionId)
Lesson 3.4: Advanced FHEVM Patterns
Duration: 75 minutesLearning Objectives
Learning Objectives
- Implement the ACL permission matrix pattern for multi-party encrypted state
- Build safe encrypted arithmetic with overflow/underflow protection
- Use sealed outputs and selective decryption for private return values
- Design encrypted state machines for complex multi-phase protocols
- Apply the v0.9+ two-phase reveal pattern
- Compose encrypted operations across multiple contracts with FHE.allowTransient
Pattern 1: ACL Permission Matrix
Pattern 1: ACL Permission Matrix
Every encrypted value has an Access Control List
Pattern 2: Safe Encrypted Arithmetic
Pattern 2: Safe Encrypted Arithmetic
FHE arithmetic does NOT revert on overflow/underflow — it silently wraps
Pattern 5: The v0.9+ Two-Phase Reveal
Pattern 5: The v0.9+ Two-Phase Reveal
The core decryption pattern for FHEVM v0.9+
Phase 1: Contract calls
FHE.makePubliclyDecryptable() and emits handlePhase 2: Client calls
publicDecrypt(handle) from @zama-fhe/relayer-sdkPhase 3: Client submits cleartext + proof, contract verifies with
FHE.checkSignatures()Homework: Build a Private Voting dApp
Estimated Time: 8 hours Objective: Build a complete Private Voting dApp with React frontend, encrypted voting, and tally reveal functionality.Requirements
1. React Voting UI
1. React Voting UI
Build a React frontend with:
- Session creation form
- Vote buttons (YES/NO)
- Results display
- Wallet connection
2. Client-Side Encryption
2. Client-Side Encryption
Integrate fhevmjs to encrypt votes in the browser before sending transactions.
3. Contract Integration
3. Contract Integration
Connect frontend to SimpleVoting contract:
- Create sessions
- Cast votes
- Request and display tally reveals
4. Error Handling
4. Error Handling
Handle edge cases:
- Wallet not connected
- Wrong network
- Expired session
- Already voted
- Unauthorized reveal attempt
Reference Implementation
Study the Universal FHEVM SDK at 0xchriswilder/fhevm-react-template for working React, Next.js, and Vue showcases.
Submission
Next Steps
Continue to Week 4
Now that you can build full-stack confidential dApps, move on to Week 4 for advanced patterns, production deployment, and your capstone project.