Service Worker support enables your wallet to run in the background, providing persistent connectivity and event handling. The
ServiceWorkerWallet exposes getVtxoManager() for VTXO lifecycle management from the worker context.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.4 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:VTXO Management in the Service Worker
Available since v0.4.8. The
VtxoManager is now accessible directly from the service worker wallet, enabling programmatic VTXO lifecycle operations alongside the automatic background renewal.VtxoManager API directly for manual control:
How Background Automation Works
When the service worker starts,VtxoManager begins eagerly:
- Auto-renewal — scans for VTXOs within the expiry threshold and renews them automatically
- Boarding sweep — settles any pending boarding UTXOs into the Ark
send, settle, renewVtxos) are serialized internally to prevent race conditions. You don’t need to coordinate between background automation and user-initiated sends.
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. As of v0.4.8, the SDK exports explicit error types for clearer failure handling:
Troubleshooting
Service Worker Not Registering
Service Worker Not Registering
If the service worker fails to register:
- Ensure the service worker file path (
serviceWorkerPath) is correct and accessible - Service workers require HTTPS (or localhost for dev)
- Check browser console for registration errors
- Verify the service worker script imports
Workerfrom@arkade-os/sdkand calls.start()
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:
- v0.4.8+: The SDK now auto-recovers from a dead service worker using a preflight PING before every operation. Persistent timeouts may indicate a network issue, not a crashed worker.
- Check that the
Workeris properly started in the service worker file - Verify network connectivity
- Check for errors in the service worker console
- If using custom error handling, check for
WorkerError(worker unresponsive) vsWalletError(wallet-level failure) to distinguish root causes
Next Steps
- VTXO Management - Manage VTXO lifecycle and renewal
- Storage Adapters - Explore different storage options
- Expo/React Native - Set up Arkade in React Native applications