Front End Guide
Overview
The frontend application provides a user interface for:
Shielded Deposits: Move tokens into the private pool
Private Transfers: Send tokens privately between shielded addresses
Withdrawals: Exit the shielded pool back to public addresses
Treasury Rates: Real-time yield data from DeFi protocols
Note: All private transactions use Pedersen commitments for amount hiding, stealth addresses for recipient hiding, and SP1 zkVM proofs for validity.
Getting Started
Prerequisites
Node.js 18+
pnpm (recommended) or npm
Installation
pnpm installSetting Up Mantle Sepolia Testnet
Before running the app, you need to add the Mantle Sepolia Testnet to your wallet:
Option 1: Automatic (via Chainlist)
Visit Chainlist
Search for "Mantle Sepolia"
Click "Add to Wallet" and approve the request
Option 2: Manual Configuration
Add the network manually in your wallet (e.g., MetaMask) with these settings:
Network Name
Mantle Sepolia Testnet
RPC URL
https://rpc.sepolia.mantle.xyz
Chain ID
5003
Currency Symbol
MNT
Block Explorer URL
https://explorer.sepolia.mantle.xyz
Getting Mock Tokens (mUSDT)
To test deposits, you'll need some mock USDT tokens on Mantle Sepolia. Follow these steps to mint mUSDT:
Navigate to the mUSDT contract on MantleScan: Mock USDT Contract
Click "Connect to Web3" to connect your wallet
Find the
mintfunction and enter:to: Your wallet addressamount: The amount to mint (in wei). For example,10000000000000000000000for 10,000 mUSDT
Click "Write" and confirm the transaction in your wallet
Once the transaction is confirmed, the mUSDT tokens will appear in your wallet and can be used for testing deposits.
Development
Open your browser at http://localhost:3000 and click Launch Now to access the shielded DEX.
Build
Architecture
Wallet SDK (/src/wallet-sdk/)
/src/wallet-sdk/)The wallet SDK provides all cryptographic and blockchain interactions:
wallet.ts
Main PrivacyWallet class combining all functionality
commitment.ts
Pedersen commitment generation and verification
keyDerivation.ts
View/spend key derivation from wallet signatures
stealthAddress.ts
Stealth address generation for private receiving
merkleTree.ts
Client-side Merkle tree for tracking commitments
contractService.ts
Smart contract interaction wrapper
Key Generation Flow
When a user connects their wallet, the following happens:
SP1 Environment Init: Initialize privacy context for ZK operations
Sign Message: User signs a message to derive privacy keys
Key Derivation: Extract view and spend keys from signature using keccak256
Stealth Address: Compute receiving address from public keys
Chain Sync: Fetch existing notes from contract events
User Flows
Deposit Flow
Input: User selects token and amount
Approve: ERC20 approval for the Gelap contract
Deposit: Generate commitment, call contract
Success: Note stored locally, balance updated
Withdrawal Flow
Select Notes: Choose UTXOs to spend
Amount: Enter withdrawal amount
Confirm: Generate ZK proof (via prover service)
Success: Public funds received
Smart Contract Integration
Contract Address (Mantle Sepolia)
Key Functions
Events to Track
AccountUpdated(bytes32 commitment, bytes encryptedMemo)
New note created
TransactionExecuted(...)
Private transaction completed
WithdrawExecuted(address receiver, ...)
Withdrawal completed
Hooks
usePrivacyWallet
usePrivacyWalletMain hook for privacy wallet state:
useTreasuryRates
useTreasuryRatesFetch live yield rates from DeFiLlama:
useContractEvents
useContractEventsSubscribe to contract events:
Environment Variables
Create a .env.local file in the project root:
Getting WalletConnect Project ID
Go to WalletConnect Cloud
Sign up or log in
Click "Create Project"
Enter project name (e.g., "Gelap Privacy")
Select "App" as project type
Copy the Project ID from the dashboard
Paste it in your
.env.localfile
Prover Service Integration
Withdrawals and private transfers require ZK proofs from the SP1 prover service.
Expected API Endpoints
Request Body
Response
Merkle Tree Specification
The client-side Merkle tree must match the on-chain implementation:
Hash Function
keccak256
Tree Depth
32 levels
Node Index
(level << 32) | index
Zero Hash[0]
keccak256(abi.encodePacked(uint256(0)))
Commitment Format
Pedersen commitments are used for amount hiding:
Where:
H= Secondary generator point on secp256k1G= Standard generator pointblinding= Random 32-byte scalar
Local Storage
The wallet persists state to localStorage:
Testing
Manual Testing Checklist
Build Verification
Troubleshooting
RPC Errors (503)
If you see "no backends available":
Check you're on the correct network (Mantle Sepolia for testnet)
Contract may not be deployed on mainnet yet
Signature Rejected
If wallet generation fails:
User rejected the signature request
Click "Retry Generation" button
Prover Unavailable
Withdrawals require a running prover service:
Set
NEXT_PUBLIC_PROVER_API_URLin.env.localMock proofs are used in development
Last updated