Skip to main content
This guide shows you how to register the HyperAuth payment service worker and submit payments from a user’s smart account. Payments are signed locally in the signer worker and submitted directly to the Pimlico bundler — no server proxy is required.

Register the payment handler

Register the payment service worker once during app initialisation, before any payment flow. This enables the browser’s Payment Request API to discover HyperAuth as a payment method.
By default registerPaymentHandler registers the service worker at /pay/sw.js with scope /pay/ and the payment method URL https://did.run/pay. Override any of these if your deployment differs:
If the browser does not support service workers, registerPaymentHandler returns { success: false, error: 'Service workers not supported' } rather than throwing.

Submit a payment

submitPayment builds and signs an ERC-4337 UserOperation that transfers tokens to the recipient, submits it to the bundler, and returns the user operation hash and an explorer URL. The vault must be unlocked to sign the payment. Signing happens inside the Dedicated Worker running enclave.wasm; the signed operation is then submitted directly to the Pimlico bundler endpoint.
If you need to constrain the payment with a UCAN delegation — for example, to enforce a spending limit — pass the delegation token:
The label field is optional and for your own record-keeping only.

Supported chains

The explorer URL is automatically set based on chainId: For any other chain ID, the URL defaults to etherscan.io.

Error handling

submitPayment throws a PluginCallError if signing fails (e.g. vault is locked) or if the bundler rejects the operation.
submitPayment does not wait for on-chain confirmation. To wait for the UserOp to be included in a block, use waitForReceipt with the returned userOpHash: