Private Prediction Markets on Zama FHEVM
A fully decentralized prediction market platform that leverages Fully Homomorphic Encryption (FHE) to keep your bet amounts completely private while maintaining transparent market outcomes. Built on Zama's FHEVM technology, Zolymarket enables users to place encrypted bets on real-world events without revealing their positions to other participants.
This is a production-ready FHEVM implementation showcasing private prediction markets with encrypted bet amounts, option selections, and oracle-based decryption.
๐ Technical Deep Dive: FHEVM_INTEGRATION.md - Complete guide on encryption workflows, smart contract patterns, relayer callbacks, and privacy architecture
- Encrypted Bet Amounts: Individual bet amounts are encrypted using FHEVM (
euint64) - no one can see how much you bet - Encrypted Option Selection: Your chosen options are encrypted on-chain using FHEVM (
euint8) - other users cannot see your positions - Encrypted User Balances: Total platform balance encrypted using FHEVM homomorphic encryption
- Encrypted Pool Totals: Total amounts staked on each option encrypted during betting period
- Oracle-Based Decryption: After bet ends, admin requests decryption and Zama oracle reveals encrypted totals for payout calculation
- Transparent Outcomes: Final results and statistics become publicly visible after decryption
- Binary Markets: Simple Yes/No predictions (e.g., "Will Bitcoin reach $100K?")
- Multiple Choice: Select from 3+ exclusive outcomes (e.g., "Who will win the championship?")
- Nested Markets: Independent propositions with Yes/No outcomes for each
- Parimutuel Odds System: Fair, pool-based payout calculation
- Real-time Statistics: Live volume tracking with encrypted data aggregation
- Category Management: Organized markets with drag-and-drop reordering
- Admin Dashboard: Complete market management interface with analytics
- Two-Step Payout System: Request payout โ Relayer decrypts โ Claim winnings
- Mobile Responsive: Seamless experience across all devices
- Smart Contract Powered: All logic runs on-chain with zero downtime
- Role-Based Access: Granular admin permissions (Super Admin, Bet Manager, Category Manager)
- Relayer Decryption: Off-chain decryption only when users claim payouts, keeping bets private throughout the betting period
- MongoDB for UX: Stores metadata like bet titles, categories, and user positions for quick filtering and sorting without exposing encrypted amounts
For a comprehensive technical guide on how Fully Homomorphic Encryption is integrated into this project, including:
- Encryption/decryption workflows
- Smart contract FHEVM patterns
- Frontend FHEVM client integration
- Relayer callback architecture
- Privacy guarantees and trade-offs
๐ Read the full guide: FHEVM_INTEGRATION.md
- User Guide: Complete guide for placing bets, claiming winnings, and using the platform
- Admin Guide: Comprehensive guide for administrators managing markets and categories
zolymarket/
โโโ hardhat/ # Smart contracts & deployment
โ โโโ contracts/ # Solidity contracts with FHEVM
โ โ โโโ BetMarketCore.sol # Core betting logic
โ โ โโโ BetMarketPayout.sol # Payout & claiming
โ โ โโโ BetMarketStats.sol # Statistics aggregation
โ โ โโโ CategoryManager.sol # Category management
โ โโโ scripts/ # Deployment scripts
โ
โโโ frontend/ # React.js application
โ โโโ src/
โ โ โโโ components/ # Reusable UI components
โ โ โโโ pages/ # Page components (Home, Dashboard, Admin)
โ โ โโโ hooks/ # Custom hooks (useWallet, useFHEVM)
โ โ โโโ lib/ # FHEVM client integration
โ โ โโโ services/ # API clients & utilities
โ โโโ vite.config.js # Build configuration
โ
โโโ backend/ # Node.js + Express API
โโโ routes/ # API endpoints
โโโ models/ # MongoDB schemas
โโโ middleware/ # Auth & validation
Before starting, you need to install the following tools:
IMPORTANT: This project requires Node.js 20 or higher (fhevmjs dependency requires node >=20)
Recommended: Use Node.js 22.x for best compatibility
Windows:
- Download Node.js from nodejs.org
- Download Node.js 22.x (Current release)
- Run the installer (
.msifile) - Follow the installation wizard (keep default settings)
- Verify installation:
node --version # Should be v22.x.x (e.g., v22.20.0) npm --version
Ubuntu/Debian:
# Update package list
sudo apt update
# Install Node.js 22.x (recommended for consistency)
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# Verify installation
node --version # Should be v22.x.x (e.g., v22.20.0)
npm --versionWindows:
- Download Git from git-scm.com
- Run the installer
- Use default settings during installation
- Verify installation:
git --version
Ubuntu/Debian:
# Install Git
sudo apt update
sudo apt install -y git
# Verify installation
git --version- Open your browser (Chrome, Firefox, or Brave)
- Go to metamask.io
- Click "Download" and install the browser extension
- Create a new wallet or import existing one
- Save your seed phrase securely!
git clone https://github.com/Farukest/Zolymarket.git
cd Zolymarket# Install Hardhat dependencies
cd hardhat && npm install && cd ..
# Install backend dependencies
cd backend && npm install && cd ..
# Install frontend dependencies
cd frontend && npm install && cd ..IMPORTANT: Copy the .env.example files and create your own .env files with your API keys.
cd backend
cp .env.example .envEdit backend/.env and update:
SEPOLIA_RPC_URL- Add your Alchemy API keyMONGODB_URI- Your MongoDB connection string (if using cloud)- Contract addresses (after deployment)
cd frontend
cp .env.example .envEdit frontend/.env and update:
VITE_FHEVM_NETWORK_URL- Add your Alchemy API keyVITE_ADMIN_ADDRESSES- Your admin wallet address- Contract addresses (after deployment)
cd hardhat
cp .env.example .envEdit hardhat/.env and update:
PRIVATE_KEY- Your wallet private key (for deploying contracts)ALCHEMY_API_KEY- Your Alchemy API keySEPOLIA_URL- Add your Alchemy API key
- Never commit
.envfiles to GitHub - Keep your private keys and API keys secret
- Use
.env.examplefiles as templates only
cd backend
npm run devNote: Configure database and contract addresses in backend/.env before starting.
cd frontend
npm run dev- Open http://localhost:5173 in your browser
- Connect your MetaMask wallet
- Switch to Sepolia Testnet in MetaMask
- Wait for FHEVM initialization (~2 seconds)
- Start placing encrypted bets! ๐
Requirements:
- MetaMask connected to Sepolia Testnet
- Sepolia ETH for gas fees
- Test USDC for placing bets
You need Sepolia ETH and Test USDC to use the platform.
Sepolia ETH:
- Use public faucets like sepoliafaucet.com
- Or contact me on Twitter: @0xflydev
Test USDC (Built-in Faucet):
The platform features an integrated faucet system for obtaining test USDC tokens. Users can claim 1000 USDC every 24 hours directly through the interface to participate in encrypted prediction markets.
How to use:
- Connect your MetaMask wallet to the platform (Sepolia Network)
- Locate the faucet button (๐ง) in the header area
- Click to claim 1000 test USDC tokens
- Use your USDC to place encrypted bets on prediction markets
- Return after 24 hours to claim again
Note: The platform is currently in beta testing. For deployment assistance or advanced configuration, reach out via Twitter or open a GitHub issue.
1. Browse Markets
Home โ Filter by Trending/New/Ending Soon โ Select a market
2. Place a Private Bet
Connect Wallet โ Select Market โ Choose Option โ Enter Amount โ Place Bet
โ
Your bet amount is encrypted and stored on-chain privately
3. Claim Winnings
Dashboard โ Claims Tab โ Request Payout โ Wait 1-2 minutes โ Claim
โ
Relayer decrypts your position and calculates your payout
1. Create a Market
Admin Panel โ Bet Management โ Create Bet โ Fill details โ Deploy
2. Resolve a Market
Admin Panel โ Bet Management โ Select Bet โ Resolve โ Select Winner
โ
Smart contract marks winning options
3. Manage Categories
Admin Panel โ Categories โ Create/Edit/Reorder categories
โ
Drag-and-drop reordering supported
Traditional Prediction Markets:
โ Bet amounts visible on-chain
โ Large bets can manipulate market sentiment
โ Privacy concerns for high-value traders
Zolymarket with FHEVM:
โ
Bet amounts encrypted before submission
โ
Smart contracts compute on encrypted data
โ
Only you can decrypt your position
โ
Market odds remain accurate without revealing individual positions
User Places $100 Bet
โ
Frontend encrypts: $100 โ 0x7f8e9a3b...
โ
Smart contract stores encrypted value
โ
Other users see: "Position exists" (amount hidden)
โ
On resolution: Relayer decrypts for payout calculation
โ
Final payout: Publicly visible (needed for claiming)
Learn more: See FHEVM_INTEGRATION.md for technical details
| Contract | Purpose | Key Features |
|---|---|---|
| BetMarketCore.sol | Core betting logic | FHEVM-encrypted bets, 3 bet types, position tracking |
| BetMarketPayout.sol | Payout management | Relayer callback, payout calculation, claiming |
| BetMarketStats.sol | Statistics aggregation | Oracle decryption, volume tracking |
| CategoryManager.sol | Category system | Hierarchical categories, display ordering |
Place Bet (Encrypted):
function placeBet(
uint256 betId,
uint256 optionIndex,
einput encryptedAmount,
bytes calldata inputProof
) external {
// Amount remains encrypted on-chain
euint64 amount = TFHE.asEuint64(encryptedAmount, inputProof);
// ... betting logic
}Request Payout (Triggers Relayer):
function requestPayout(uint256 betId) external {
// Emit event for relayer to process
emit PayoutRequested(betId, msg.sender);
}Claim Payout (After Decryption):
function claimPayout(uint256 betId) external {
uint256 payout = payouts[betId][msg.sender];
// Transfer USDC to winner
usdc.transfer(msg.sender, payout);
}- Solidity 0.8.24 - Smart contract language
- Zama FHEVM - Fully homomorphic encryption library
- Hardhat - Development framework
- fhEVM.sol - FHEVM Solidity library
- React 18 - UI framework
- Vite - Build tool & dev server
- Ethers.js 6 - Web3 library
- fhevmjs - FHEVM client library
- TailwindCSS - Styling framework
- React Router - Navigation
- Lucide React - Icon library
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database for metadata
- Mongoose - ODM library
- FHEVM-encrypted bet placement
- Three bet types (Binary, Multiple, Nested)
- Relayer callback system for payouts
- Admin panel with analytics
- Category management with drag-and-drop
- User dashboard with position tracking
- MongoDB winner/loser tracking
- Mobile-responsive UI
- Dark mode support
- Social features (comments, user profiles)
- Advanced analytics charts
- Multi-language support
- Mobile app (React Native)
- On-chain governance
- Liquidity pools
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style and conventions
- Add comments for complex logic
- Test all changes thoroughly
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub Repository: github.com/Farukest/Zolymarket
- Twitter: @0xflydev
- Zama FHEVM Docs: docs.zama.ai/fhevm
- FHEVM Integration Guide: FHEVM_INTEGRATION.md
- This project is experimental and deployed on testnets only
- Not financial advice - use at your own risk
- Ensure compliance with local regulations before using prediction markets
- Smart contracts are unaudited - do not use with real funds on mainnet
- Zama - For pioneering FHEVM technology and making privacy-preserving smart contracts possible
- React & Vite communities - For excellent developer tools
- Open source contributors - For inspiration and shared knowledge
- Issues: GitHub Issues
- Twitter: @0xflydev
- GitHub: @Farukest
Built with โค๏ธ using Zama FHEVM, React, and Solidity
โญ Star this repo if you find it useful!
