Skip to main content
Defined in the Base Account SDK
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

Use prepareCharge 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)
For standard backend subscription management, use charge() instead.

Parameters

id
string
required
The subscription ID (permission hash) returned from subscribe().Pattern: ^0x[0-9a-fA-F]{64}$
amount
string | 'max-remaining-charge'
required
Amount to charge (e.g., “10.50”) or ‘max-remaining-charge’ for the full remaining amount in the current period.
testnet
boolean
Must match the testnet setting used in the original subscribe call. Default: false

Returns

result
PrepareChargeResult
Array of transaction calls to execute the charge.
The returned array contains:
  • An approval call (if the permission is not yet active)
  • A spend call to charge the subscription

Error Handling

Comparison with charge()

Migration to charge()

If you’re currently using prepareCharge in a Node.js backend, consider migrating to charge():
Before (prepareCharge)
After (charge)

Charge

Automatic charging with CDP

Check Status

Verify subscription before charging

Custom Revoke

Advanced revoke execution