New Stylus template: ZK based token contracts
Yash KumarWe have added support for creating and deploying ZK Proof based token contracts with Stylus. The templates provide you with Stylus contracts, ZK circuit files, and a ready-to-deploy Next.js app + API for proof generation and minting.
This guide walks you through building a privacy-preserving ERC721 token system using Zero-Knowledge proofs on Arbitrum Stylus. Users can mint tokens by proving they own a minimum amount of ETH without revealing their exact balance.
What You'll Build
- ZK Circuit: Proves token ownership without revealing exact balances
 - Stylus Contract: Rust-based ERC721 contract that verifies ZK proofs
 - Frontend: Next.js app for generating proofs and minting tokens
 - Oracle System: Secure balance verification mechanism
 
Prerequisites
- Node.js (>= 20.18.0)
 - pnpm package manager
 - Rust with cargo
 - circom for ZK circuits
 - Stylus CLI for contract deployment
 
Step 1: Project Setup
Using thirdweb CLI
Select "Stylus ZK ERC721" from the dropdown menu. This will:
- Clone the repository to your machine
 - Set up the project structure
 - Install basic dependencies
 
Manual Setup (Alternative)
Step 2: Install Dependencies
Install dependencies for all components:
Step 3: Generate Cryptographic Keys
Run the setup script to generate oracle keys and build the ZK circuit:
This script will:
- Generate a random oracle secret key
 - Inject the secret into the ZK circuit
 - Compile the circuit with circom
 - Generate proving and verification keys
 - Create the trusted setup for Groth16
 
⚠️ Important: The oracle secret is critical for security. Keep it private!
Step 4: Deploy the Contract
Using thirdweb CLI
Using Stylus CLI (Alternative)
Copy the deployed contract address - you'll need it for the frontend.
Step 5: Configure the Frontend
Update the contract address in your frontend:
Create environment file:
Step 6: Run the Application
Step 7: Test the System
- Connect Wallet: Connect to Arbitrum Sepolia testnet
 - Generate Proof: Click "Generate ZK Proof" - this proves you have sufficient balance
 - Mint Tokens: Use the proof to mint ERC721 tokens
 
Customizing the ZK Logic
Understanding the Circuit
The core circuit (circuits/token_ownership.circom) has these components:
Customization Examples
1. Change Balance Threshold Logic
Replace the balance check with custom logic:
2. Add Multiple Token Support
Extend the circuit to verify multiple token balances:
3. Add Time-Based Constraints
Add expiration logic to proofs:
Rebuilding After Changes
After modifying the circuit:
Additional Resources
Support
Need help? Please reach out to our support team.