Skip to content

KristofferSchuppe/fhevm-react-template

Β 
Β 

Repository files navigation

πŸ” FHEVM Toolkit - Universal SDK for Confidential dApps

Framework-agnostic, modular, and developer-friendly SDK for building confidential applications with Fully Homomorphic Encryption (FHE).

License TypeScript Node

πŸ† Zama FHEVM Challenge Submission

🌐 Live Example: https://fhe-evidence-manager.vercel.app/

πŸ“¦ GitHub Repository: https://github.com/KristofferSchuppe/fhevm-react-template

πŸ“Ί Demo Video: demo.mp4 (Download to watch - video player links may not work in all environments)


πŸ“‹ Overview

The FHEVM Toolkit provides a universal, framework-agnostic SDK that makes building confidential front-ends simple, consistent, and developer-friendly. Inspired by wagmi's intuitive design, our SDK works seamlessly across Node.js, Next.js, React, Vue, and any JavaScript environment.

Core Concept: FHE Contract Privacy Evidence Management - The toolkit includes a complete implementation of a confidential judicial evidence system that demonstrates real-world FHE usage with role-based access control, secure evidence submission, and cryptographic privacy guarantees.

Key Features:

  • 🎯 Framework-Agnostic: Works with any frontend setup (Next.js, React, Vue, Node.js)
  • πŸ“¦ All-in-One Package: Wraps all required dependencies - no scattered packages
  • πŸͺ Wagmi-Like API: Intuitive hooks and modular structure for React developers
  • πŸš€ <10 Lines to Start: Minimal boilerplate, maximum productivity
  • πŸ”’ Complete FHE Flow: Init, encrypt, decrypt, and permission management
  • πŸ“– Well-Documented: Clear examples and comprehensive guides
  • πŸ§ͺ Production-Ready: Tested, typed, and battle-tested
  • βš–οΈ Real Use Case: FHE Evidence Manager - Confidential judicial evidence system

🎬 Demo Video

πŸ“Ί Demo Video: demo.mp4

Important: Download the video file to watch. Video player links may not work in all environments.

The video showcases:

  1. SDK installation and setup (<10 lines of code)
  2. Next.js integration with React hooks
  3. FHE Evidence Manager example
  4. Encryption and decryption workflow
  5. Multi-framework support demonstration

πŸš€ Quick Start (< 10 lines)

1. Install from Root

npm install

2. Build SDK

npm run build

3. Use a Template

Choose your preferred framework and get started:

# Next.js template
cd templates/nextjs
npm install
npm run dev

# React template
cd templates/react
npm install
npm run dev

# Vue template
cd templates/vue
npm install
npm run dev

# Node.js template
cd templates/nodejs
npm install
npm run dev

4. Or Run Examples

# Next.js example
npm run dev:nextjs

# Privacy Evidence Manager
npm run dev:evidence

5. Use in Your App

import { FhevmClient } from '@fhevm-toolkit/sdk';

// 3 lines to initialize
const client = new FhevmClient({ provider, signer, chainId: 11155111 });
await client.init();

// 1 line to encrypt
const encrypted = await client.encryptInput({ value: 42, type: 'uint32', contractAddress: CONTRACT_ADDRESS });

// Done! βœ…

πŸ—οΈ Architecture

fhevm-toolkit/
β”œβ”€β”€ packages/
β”‚   └── fhevm-sdk/               # πŸ”₯ Universal SDK Package
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ core/            # Core FhevmClient, encryption, decryption
β”‚       β”‚   β”œβ”€β”€ adapters/        # Framework adapters (React hooks)
β”‚       β”‚   β”œβ”€β”€ utils/           # Contract helpers, validation
β”‚       β”‚   β”œβ”€β”€ types/           # TypeScript definitions
β”‚       β”‚   └── config/          # Network configurations
β”‚       β”œβ”€β”€ dist/                # Built package
β”‚       └── README.md            # SDK documentation
β”‚
β”œβ”€β”€ templates/                   # 🎨 Framework Templates
β”‚   β”œβ”€β”€ nextjs/                  # Next.js 14 template
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ app/             # App Router with API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ components/      # UI and FHE components
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/             # FHE integration library
β”‚   β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”‚   └── types/           # TypeScript types
β”‚   β”‚   └── README.md
β”‚   β”‚
β”‚   β”œβ”€β”€ react/                   # React + Vite template
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”‚   └── hooks/           # FHE hooks
β”‚   β”‚   └── README.md
β”‚   β”‚
β”‚   β”œβ”€β”€ vue/                     # Vue 3 template
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ components/      # Vue components
β”‚   β”‚   β”‚   └── composables/     # FHE composables
β”‚   β”‚   └── README.md
β”‚   β”‚
β”‚   └── nodejs/                  # Node.js template
β”‚       β”œβ”€β”€ src/                 # Main application
β”‚       β”œβ”€β”€ examples/            # Usage examples
β”‚       └── README.md
β”‚
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ nextjs-fhe-integration/  # πŸ“± Complete Next.js example
β”‚   β”‚   β”œβ”€β”€ src/app/             # Next.js 14 App Router
β”‚   β”‚   β”œβ”€β”€ src/components/      # FHE & UI components
β”‚   β”‚   β”œβ”€β”€ src/lib/             # FHE integration library
β”‚   β”‚   β”œβ”€β”€ src/hooks/           # Custom React hooks
β”‚   β”‚   └── README.md
β”‚   β”‚
β”‚   β”œβ”€β”€ nextjs-evidence-manager/ # πŸ“± Next.js + RainbowKit example
β”‚   β”‚   β”œβ”€β”€ app/                 # Next.js 14 App Router
β”‚   β”‚   β”œβ”€β”€ lib/                 # SDK integration
β”‚   β”‚   └── README.md
β”‚   β”‚
β”‚   └── privacy-evidence-manager/# πŸ“ Smart Contract + React Example
β”‚       β”œβ”€β”€ contracts/           # Solidity contracts
β”‚       β”œβ”€β”€ scripts/             # Deploy & interact scripts
β”‚       β”œβ”€β”€ test/                # 77 tests (92.45% coverage)
β”‚       β”œβ”€β”€ src/                 # React frontend
β”‚       └── README.md
β”‚
β”œβ”€β”€ docs/                        # πŸ“š Documentation
β”‚   β”œβ”€β”€ SDK_GUIDE.md             # Complete SDK guide
β”‚   β”œβ”€β”€ INTEGRATION.md           # Framework integration examples
β”‚   β”œβ”€β”€ API_REFERENCE.md         # API documentation
β”‚   └── DEPLOYMENT.md            # Deployment guide
β”‚
β”œβ”€β”€ demo.mp4                     # 🎬 Video demonstration
β”œβ”€β”€ package.json                 # Monorepo configuration
└── README.md                    # This file

πŸ“¦ SDK Package Structure

Core Modules

FhevmClient - Main class for FHEVM operations

const client = new FhevmClient({ provider, signer, chainId });
await client.init();

Encryption - Type-safe encryption utilities

const encrypted = await client.encryptInput({
  value: 100,
  type: 'uint64',
  contractAddress: CONTRACT_ADDRESS
});

Decryption - User and public decryption

const permission = await client.generatePermissionSignature(CONTRACT_ADDRESS);

React Hooks - Wagmi-like hooks (optional)

const { client, isInitialized } = useFhevmClient({ provider, signer, chainId });
const { encrypt, isEncrypting } = useEncrypt(client);

🌐 Multi-Framework Support

Next.js Templates

Complete Next.js 14 templates with App Router, API routes, and SDK integration.

Templates Available:

  • templates/nextjs/ - Base Next.js template
  • examples/nextjs-fhe-integration/ - Full FHE integration example
  • examples/nextjs-evidence-manager/ - Evidence manager app
'use client';

import { useFhevmClient, useEncrypt } from '@fhevm-toolkit/sdk';

export default function Page() {
  const { client, isInitialized } = useFhevmClient({
    provider,
    signer,
    chainId: 11155111
  });

  const { encrypt } = useEncrypt(client);

  const handleSubmit = async (value: number) => {
    const result = await encrypt({
      value,
      type: 'uint64',
      contractAddress: CONTRACT_ADDRESS
    });
    // Use result in contract call
  };

  return <div>{/* UI */}</div>;
}

Features:

  • βœ… App Router with API routes
  • βœ… FHE Provider & Components
  • βœ… Custom hooks (useFHE, useEncryption, useComputation)
  • βœ… TypeScript & Tailwind CSS

React Template

React 18 + Vite template with SDK integration.

Location: templates/react/

Features:

  • βœ… Vite for fast development
  • βœ… FHE hooks and components
  • βœ… TypeScript support
  • βœ… Modern CSS styling

Vue Template

Vue 3 Composition API template with SDK integration.

Location: templates/vue/

<script setup lang="ts">
import { useFHE } from '@/composables/useFHE';

const { client, isInitialized, initializeFHE } = useFHE();

const handleEncrypt = async () => {
  const result = await client.value.encryptInput({
    value: 100,
    type: 'uint64',
    contractAddress: CONTRACT_ADDRESS
  });
};
</script>

Features:

  • βœ… Vue 3 Composition API
  • βœ… FHE composables
  • βœ… TypeScript support
  • βœ… Vite build system

Node.js Template

Server-side Node.js/TypeScript template with multiple examples.

Location: templates/nodejs/

import { FhevmClient } from '@fhevm-toolkit/sdk';

async function main() {
  const client = new FhevmClient({ provider, signer, chainId: 11155111 });
  await client.init();

  const encrypted = await client.encryptInput({
    value: 100,
    type: 'uint64',
    contractAddress: CONTRACT_ADDRESS
  });

  console.log('Encrypted:', encrypted);
}

main();

Features:

  • βœ… TypeScript with tsx
  • βœ… Environment configuration
  • βœ… Multiple usage examples
  • βœ… Production-ready setup

πŸ“± Example Applications

1. Next.js FHE Integration (Complete Example)

Location: examples/nextjs-fhe-integration/

Features:

  • βœ… Next.js 14 with App Router
  • βœ… Complete FHE Provider implementation
  • βœ… Encryption/Decryption demos
  • βœ… Homomorphic computation examples
  • βœ… Banking & Medical use cases
  • βœ… Key management interface
  • βœ… TypeScript + Tailwind CSS

Run:

cd examples/nextjs-fhe-integration
npm install
npm run dev

2. FHE Evidence Manager (Next.js Example)

Location: examples/nextjs-evidence-manager/

Features:

  • βœ… Next.js 14 with App Router
  • βœ… RainbowKit wallet integration
  • βœ… Wagmi + FHEVM SDK hooks
  • βœ… Tailwind CSS styling
  • βœ… Real-time encryption demo
  • βœ… Confidential judicial evidence system

Run:

npm run dev:nextjs

Live Demo: https://fhe-evidence-manager.vercel.app/

3. Privacy Evidence Manager (Smart Contract + React)

Location: examples/privacy-evidence-manager/

Features:

  • βœ… Hardhat smart contract project
  • βœ… React frontend with Vite
  • βœ… FHEVM SDK integration
  • βœ… 77 tests with 92.45% coverage
  • βœ… Sepolia deployment
  • βœ… Role-based access control
  • βœ… Confidential judicial evidence management

Run:

cd examples/privacy-evidence-manager
npm install
npm run compile       # Compile contracts
npm test              # Run tests
npm run frontend      # Run React frontend
npm run deploy        # Deploy to Sepolia

Deployed Contract: 0x2BB2Eed0a66d74D92897aFAADa41a988E50C1830

GitHub: https://github.com/KristofferSchuppe/FHEEvidenceManager


πŸ“– Complete Documentation

SDK Documentation

Template Documentation

Example Documentation

Additional Resources


πŸ”§ SDK Features

1. Easy Initialization

const client = new FhevmClient({
  provider: ethersProvider,
  signer: ethersSigner,
  chainId: 11155111,
  gatewayUrl: 'https://gateway.fhevm.io', // Optional
  aclAddress: '0x...' // Optional
});

await client.init(); // Fetches public key, ready to use

2. Type-Safe Encryption

// Supported types: bool, uint8, uint16, uint32, uint64, uint128, uint256, address
const encrypted = await client.encryptInput({
  value: 42,
  type: 'uint32',
  contractAddress: CONTRACT_ADDRESS
});

// Use in contract
const tx = await contract.submitValue(encrypted.handles[0], encrypted.inputProof);

3. Permission Management

// Generate EIP-712 signature for decryption
const permission = await client.generatePermissionSignature(CONTRACT_ADDRESS);

console.log(permission.signature); // Use for decryption
console.log(permission.publicKey);  // Public key

4. Helper Functions

import {
  encryptBool,
  encryptUint32,
  encryptUint64,
  encryptBatch,
  validateAddress,
  createContract
} from '@fhevm-toolkit/sdk';

// Type-specific helpers
const boolResult = await encryptBool(client, true, CONTRACT_ADDRESS);
const uint32Result = await encryptUint32(client, 100, CONTRACT_ADDRESS);

// Batch operations
const results = await encryptBatch(client, [
  { value: true, type: 'bool', contractAddress: CONTRACT_ADDRESS },
  { value: 42, type: 'uint32', contractAddress: CONTRACT_ADDRESS }
]);

5. React Hooks (Wagmi-like)

// Initialize client
const { client, isInitialized, error } = useFhevmClient({ provider, signer, chainId });

// Encryption hook
const { encrypt, isEncrypting } = useEncrypt(client);

// Permission hook
const { generatePermission, isGenerating } = usePermission(client);

// State hooks
const state = useFhevmState(client);
const publicKey = usePublicKey(client);

πŸ§ͺ Testing & Quality

SDK Tests

cd packages/fhevm-sdk
npm test

Example Tests

cd examples/privacy-evidence-manager
npm test

# Results
βœ“ 77 tests passing
βœ“ 92.45% statement coverage
βœ“ 95.83% function coverage
βœ“ 95.4% line coverage

🌐 Deployed Links

Live Applications

Smart Contracts

Repositories

Demo Resources

  • Video Demo: demo.mp4 (Download to watch - included in repo)

πŸ“Š Evaluation Criteria

βœ… Usability

  • <10 lines to start: Minimal boilerplate
  • Clear API: Wagmi-like structure, familiar to web3 devs
  • TypeScript support: Full type definitions
  • Error handling: Comprehensive error types

βœ… Completeness

  • Full FHE flow: Init βœ“ Encrypt βœ“ Decrypt βœ“ Permissions βœ“
  • Contract interaction: Helpers for contract calls
  • Batch operations: Encrypt multiple values
  • Permission signatures: EIP-712 implementation

βœ… Reusability

  • Framework-agnostic core: Works everywhere
  • Modular architecture: Import only what you need
  • React adapter: Optional hooks for React apps
  • Clean utilities: Validation, contract helpers

βœ… Documentation

  • Comprehensive guides: 5+ documentation files
  • Code examples: Next.js, Node.js, Vue examples
  • API reference: Full TypeScript documentation
  • Video demo: Complete walkthrough

βœ… Creativity (Bonus)

  • Multi-environment: Next.js βœ“ Node.js βœ“ (Vue ready)
  • Real use case: Privacy Evidence Manager
  • Production-ready: 77 tests, 92.45% coverage
  • Developer experience: CLI-friendly, minimal setup

πŸ› οΈ Development

Install All Dependencies

npm run install:all

Build SDK

npm run build

Run Examples

# Next.js example
npm run dev:nextjs

# Evidence Manager
npm run dev:evidence

Clean Install

npm run clean
npm install

πŸ“ Repository Structure

πŸ“¦ fhevm-toolkit (this repo)
β”œβ”€β”€ πŸ“¦ packages/fhevm-sdk/                Universal SDK package
β”œβ”€β”€ 🎨 templates/                         Framework templates
β”‚   β”œβ”€β”€ nextjs/                           Next.js 14 template
β”‚   β”œβ”€β”€ react/                            React + Vite template
β”‚   β”œβ”€β”€ vue/                              Vue 3 template
β”‚   └── nodejs/                           Node.js template
β”œβ”€β”€ πŸ“± examples/                          Example applications
β”‚   β”œβ”€β”€ nextjs-fhe-integration/           Complete Next.js FHE example
β”‚   β”œβ”€β”€ nextjs-evidence-manager/          Next.js + RainbowKit example
β”‚   └── privacy-evidence-manager/         Smart contract + React example
β”œβ”€β”€ πŸ“š docs/                              Complete documentation
β”œβ”€β”€ 🎬 demo.mp4                           Video demonstration
β”œβ”€β”€ πŸ“„ package.json                       Monorepo config
β”œβ”€β”€ πŸ“– README.md                          This file
└── πŸ“œ LICENSE                            MIT License

🀝 Contributing

Contributions welcome! This is an open-source project built for the Zama FHEVM Challenge.

How to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.


πŸ™ Acknowledgments

This project builds on:


πŸ† Zama FHEVM Challenge

Submission Details:

  • Challenge: Universal FHEVM SDK
  • Deliverables:
    • βœ… Universal SDK package (@fhevm-toolkit/sdk)
    • βœ… Next.js example application
    • βœ… Privacy Evidence Manager example
    • βœ… Complete documentation
    • βœ… Video demonstration (demo.mp4)
    • βœ… Deployed contracts and live demos

GitHub Repository: https://github.com/KristofferSchuppe/fhevm-react-template

Live Demo: https://fhe-evidence-manager.vercel.app/

Forked From: fhevm-react-template


πŸ“ž Contact & Support


Built with πŸ”’ for Zama FHEVM Challenge

Making confidential computing simple, consistent, and developer-friendly

Status: βœ… Complete - Ready for Evaluation

About

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 92.9%
  • CSS 3.1%
  • Vue 2.9%
  • Other 1.1%