Most developers should use
charge() instead, which handles execution automatically using CDP wallets. This function is for advanced use cases requiring custom transaction handling.The
prepareCharge function prepares the necessary transaction calls to charge a subscription. It returns the array of call data objects to execute the charge through wallet_sendCalls or eth_sendTransaction. This gives you programmatic control over when and how to execute subscription charges.When to Use This
UseprepareCharge only if you need:
- Custom wallet infrastructure (not using CDP)
- Manual transaction control
- Integration with existing wallet systems
- Client-side charging (though this is uncommon)
charge() instead.
Parameters
The subscription ID (permission hash) returned from subscribe().Pattern:
^0x[0-9a-fA-F]{64}$Amount to charge (e.g., “10.50”) or ‘max-remaining-charge’ for the full remaining amount in the current period.
Must match the testnet setting used in the original subscribe call. Default: false
Returns
Array of transaction calls to execute the charge.
- An approval call (if the permission is not yet active)
- A spend call to charge the subscription
Error Handling
Comparison with charge()
- Using prepareCharge (Advanced)
- Using charge() (Recommended)
Migration to charge()
If you’re currently usingprepareCharge in a Node.js backend, consider migrating to charge():
Before (prepareCharge)
After (charge)
Related Functions
Charge
Automatic charging with CDP
Check Status
Verify subscription before charging
Custom Revoke
Advanced revoke execution