A complete template for building privacy-preserving ERC20 token minting using Zero-Knowledge proofs and Arbitrum Stylus.
- Privacy-First: Prove token ownership without revealing exact balances
- Zero-Knowledge Proofs: Uses Groth16 for efficient verification
- Arbitrum Stylus: Rust-based smart contracts with EVM compatibility
- thirdweb Integration: Easy wallet connection and contract interaction
- Full-Stack Template: Complete setup with frontend, backend, and contracts
stylus-zk-mint/
├── contracts/ # Arbitrum Stylus contracts (Rust)
├── circuits/ # ZK circuits for token ownership proof
├── app/ # Next.js frontend with API routes
└── setup.sh # One-command setup script
- Node.js (>= 20.18.0)
- pnpm package manager
- Rust with cargo
- circom for ZK circuits
- Stylus CLI for contract deployment
-
Clone the template:
git clone git@github.com:thirdweb-example/stylus-zk-mint.git cd stylus-zk-mint -
Run setup script:
chmod +x setup.sh ./setup.sh
-
Deploy the contract:
cd contracts npx thirdweb@latest deploy-stylus -k <THIRDWEB SECRET KEY> # Copy the deployed contract address
Arkworks address: 0x2e9e7b36619fed922da9e54ccb0873d4a0bc6594 (Arbitrum Sepolia)
-
Update app configuration:
cd ../app # Edit pages/index.tsx and update ZK_MINT_CONTRACT_ADDRESS
-
Start the app:
pnpm dev # Visit http://localhost:3000
- Connect wallet to the dApp
- Enter a token contract address and minimum balance
- Generate ZK proof (proves you own ≥ X tokens without revealing exact amount)
- Mint ERC20 tokens using the proof
- Frontend calls API route with user's wallet address and token requirements
- API route checks actual on-chain token balance via RPC
- ZK Circuit generates proof that
actual_balance >= required_balance - Smart Contract verifies the proof and mints ERC20 tokens
- Balance Privacy: Your exact token balance is never revealed
- Identity Privacy: Proves membership without revealing which member
- Replay Protection: Each proof includes a unique nullifier
cd contracts
cargo testcd circuits
pnpm run buildcd app
pnpm devcd contracts
cargo stylus deploy --endpoint arbitrum-sepoliacd app
vercel deployCreate app/.env.local:
RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
SUPPORTED_TOKENS=0x...,0x... # Optional: restrict to specific tokens- Token Requirements: Modify the circuit in
circuits/token_ownership.circom - UI Styling: Update
app/styles/Home.module.css - Contract Logic: Modify
contracts/src/lib.rs
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This is a template for educational and development purposes. Before deploying to production:
- Audit your ZK circuit thoroughly
- Test with various edge cases
- Consider formal verification of your contracts
- Review all cryptographic implementations