A privacy-preserving survey application built with React and Zama's Fully Homomorphic Encryption (FHE) technology. This application allows users to submit survey responses that remain encrypted on-chain, enabling privacy-preserving analytics.
Live Demo: https://zama-survey-terminal.vercel.app/
- Privacy-First: Survey responses are encrypted client-side using FHE before blockchain submission
- Terminal Interface: Interactive terminal UI built with xterm.js
- Smart Contract: Solidity contract using Zama's FHEVM for encrypted data storage
- Web3 Integration: MetaMask wallet connection and Ethereum interaction
- Zama FHEVM on Sepolia: Deploys to Sepolia testnet with Zama's FHE capabilities (chainId 11155111)
- React TypeScript application with modern UI
- xterm.js for terminal interface
- Tailwind CSS for styling
- ethers.js for blockchain interaction
- @zama-fhe/relayer-sdk and tfhe for FHE operations
- Solidity contract using
@fhevm/solidity
- Stores encrypted survey responses as
euint8[5]
arrays - Data remains encrypted on-chain for privacy
- Deploys to Sepolia testnet with Zama's FHEVM infrastructure
- ChainId: 11155111
- Uses Zama's FHE-enabled Sepolia configuration for encrypted computations
- Node.js and npm
- MetaMask browser extension
- Sepolia testnet configuration in MetaMask (with Zama FHEVM support)
After deployment, update the contract address in src/App.tsx
.
├── src/
│ ├── App.tsx # Main application component
│ ├── components/Terminal.tsx # Terminal interface component
│ ├── hooks/useWallet.ts # MetaMask wallet hook
│ └── abi/ZamaSurvey.json # Contract ABI
├── hardhat/
│ ├── contracts/ZamaSurvey.sol # FHE survey contract
│ ├── scripts/deploy.ts # Deployment script
│ └── hardhat.config.ts # Hardhat configuration
- React 19.1.0
- TypeScript 4.9.5
- ethers.js 6.15.0
- xterm.js 5.3.0
- Tailwind CSS 3.4.17
- @zama-fhe/relayer-sdk 0.1.1
- tfhe 1.3.1
- Hardhat 2.25.0
- @fhevm/solidity 0.7.0
- @fhevm/hardhat-plugin 0.0.1-0
- @openzeppelin/contracts 5.0.0
- Survey Setup: The terminal presents survey questions to users
- Response Collection: User answers are collected through the terminal interface
- FHE Encryption: Responses are encrypted client-side using Zama's FHE technology
- Blockchain Storage: Encrypted responses are submitted to the smart contract
- Privacy Preservation: Data remains encrypted on-chain, enabling privacy-preserving analytics
Add Sepolia testnet to MetaMask for Zama FHEVM:
- Network Name: Sepolia Testnet (Zama FHEVM)
- RPC URL: https://rpc1.sepolia.org (or your preferred Sepolia RPC)
- Chain ID: 11155111
- Currency Symbol: ETH
Note: This project uses Zama's FHEVM infrastructure on Sepolia, which enables fully homomorphic encryption operations on the Ethereum Sepolia testnet.
The frontend uses Jest and React Testing Library for unit and integration tests.
# Run all frontend tests
npm test
# Run tests in watch mode (default)
npm test
# Run tests once and exit
npm test -- --watchAll=false
# Run tests with coverage
npm test -- --coverage --watchAll=false
Test Structure:
- Unit tests for React components using
@testing-library/react
- Mock wallet interactions for isolated testing
- Integration tests for terminal functionality
- Jest configuration extends
react-app
preset
The Hardhat environment supports comprehensive smart contract testing.
cd hardhat
# Run all contract tests
npm test
# or
npx hardhat test
# Run tests with gas reporting
npx hardhat test --reporter gas
# Run specific test file
npx hardhat test test/ZamaSurvey.test.js
# Run tests on specific network
npx hardhat test --network localhost
Test Framework:
- Mocha as test runner
- Chai for assertions
- Hardhat Network for blockchain simulation
- Waffle for contract testing utilities
- Typechain for type-safe contract interactions
FHE Testing Considerations:
- Mock FHE operations for unit tests
- Test encrypted data handling carefully
- Verify access control and permissions
- Test decryption oracle interactions
# Frontend linting (automatic via react-scripts)
npm run build # Includes linting
# Smart contract linting
cd hardhat
npm run lint # Run all linting
npm run lint:sol # Solidity linting only
npm run lint:ts # TypeScript linting only
# Code formatting
npm run prettier:check # Check formatting
npm run prettier:write # Fix formatting
Generate coverage reports to ensure comprehensive testing:
# Frontend coverage
npm test -- --coverage --watchAll=false
# View coverage report
open coverage/lcov-report/index.html
For automated testing in GitHub Actions or similar:
# Frontend tests (headless)
npm test -- --watchAll=false --coverage
# Smart contract tests
cd hardhat && npm test
# Full test suite
npm test -- --watchAll=false && cd hardhat && npm test
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request