Service Worker support is a new feature in v0.3. It enables your wallet to run in the background, providing persistent connectivity and event handling.
Overview
Running your wallet in a service worker enables:- Background Processing: Keep your wallet active even when the main application is closed
- Persistent Storage: Use IndexedDB for reliable data persistence
- Event Handling: Process incoming payments and settlements in the background
- Improved UX: Faster response times and better reliability
Quick Setup
The v0.3 SDK provides ultra-simplified service worker setup with automatic registration and identity management:Service Worker Implementation
Create a service worker file that handles communication:Worker class automatically:
- Handles message routing
- Manages wallet state
- Processes events
- Handles cleanup
Example: Storage and Identity Management
Here’s a complete example with storage and identity management:Using IndexedDB Storage
For service workers, IndexedDB is recommended over LocalStorage:Handling Events
Service workers can process wallet events in the background:Advanced: Custom Service Worker
If you need custom service worker logic, you can extend theWorker class:
Best Practices
Storage Selection
Storage Selection
Always use IndexedDB for service worker wallets:
Identity Management
Identity Management
Store your identity securely and load it on initialization:
Error Handling
Error Handling
Implement proper error handling for service worker operations:
Troubleshooting
Service Worker Not Registering
Service Worker Not Registering
If you encounter IndexedDB errors:
- Check browser console for specific error messages
- Ensure the database name and version are consistent
- Clear browser data if the database schema changed
IndexedDB Errors
IndexedDB Errors
If you encounter IndexedDB errors:
- Check browser console for specific error messages
- Ensure the database name and version are consistent
- Clear browser data if the database schema changed
Message Timeout
Message Timeout
If you experience message timeouts:
- Check that the Worker is properly started in the service worker
- Verify network connectivity
- Check for errors in the service worker console
Next Steps
- Storage Adapters - Explore different storage options
- Expo/React Native - Set up Arkade in React Native applications