Overview
The SDK provides WebAssembly bindings that allow you to use zero-knowledge proofs directly in the browser. There are three main integration patterns:- Native Web - Direct browser usage without a bundler
- Vite - Integration with Vite bundler
- Webpack - Integration with Webpack bundler
- Node.js - Server-side usage
Installation
Native Web Integration
Setup
For native web usage without a bundler, you need to initialize the WASM module:Complete Example
Here’s a complete working example for native web:Running the Example
Vite Integration
Setup
Vite handles WASM initialization automatically:Complete Example
Vite Configuration
Running with Vite
Webpack Integration
Webpack Configuration
Webpack requires special configuration for WASM:Usage with Webpack
Running with Webpack
Node.js Integration
For server-side usage:Advanced Usage Patterns
Lazy Loading WASM
For better initial load performance:Worker Thread Integration
Offload proof generation to a worker:Testing Your Integration
Automated Testing with Playwright
Troubleshooting
WASM Not Loading
If WASM fails to load:-
Check that your server serves
.wasmfiles with the correct MIME type: - Ensure CORS headers are set if loading from a different origin
- Check browser console for initialization errors
Bundler Issues
For Vite:- Add
@solana/zk-sdktooptimizeDeps.exclude - Use the
/bundlerexport path
- Enable
experiments.asyncWebAssembly - Use Webpack 5 or later
Performance Optimization
- Lazy load the WASM module only when needed
- Use workers for proof generation to avoid blocking UI
- Cache the initialized WASM module
- Preload WASM in the HTML head:
Next Steps
- See JavaScript Usage for API examples
- See Rust Usage for native implementation
- Refer to the JavaScript SDK Overview for detailed API documentation