Node.js Only: This function uses CDP (Coinbase Developer Platform) server wallets and is only available in Node.js environments. For browser/client-side applications, use
prepareRevoke instead.The
revoke function cancels subscriptions automatically from your backend. It uses a CDP smart wallet as the subscription owner to execute the revocation transaction, handling all details including wallet management, transaction signing, and optional gas sponsorship.How It Works
When you callrevoke(), the function:
- Initializes a CDP client with your credentials
- Retrieves the existing smart wallet (subscription owner)
- Prepares the revoke transaction call
- Executes the revocation using the smart wallet
- Optionally uses a paymaster for gas sponsorship
- Returns the transaction hash
Parameters
The subscription ID (permission hash) returned from
subscribe().Pattern: ^0x[0-9a-fA-F]{64}$Whether to use Base Sepolia testnet. Must match the network used in
subscribe(). Default: falseCDP API key ID. Falls back to
CDP_API_KEY_ID environment variable.CDP API key secret. Falls back to
CDP_API_KEY_SECRET environment variable.CDP wallet secret. Falls back to
CDP_WALLET_SECRET environment variable.Optional custom wallet name for the CDP smart wallet. Default: “subscription owner”
Use Default: Most applications should omit this parameter and use the default. Only specify if you used a custom name in
getOrCreateSubscriptionOwnerWallet().Paymaster URL for transaction sponsorship (gasless transactions). Falls back to
PAYMASTER_URL environment variable.Returns
Revoke execution result.
Setup
Before usingrevoke(), you need CDP credentials. Get them from the CDP Portal.
Set as environment variables:
Error Handling
Always wraprevoke() calls in try-catch blocks:
Common Use Cases
- User Cancellation Request
- Policy Violation
- Administrative Action
Common Errors
Missing CDP Credentials
Missing CDP Credentials
CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET are set as environment variables or passed as parameters.Subscription Not Found
Subscription Not Found
Wallet Does Not Exist
Wallet Does Not Exist
getOrCreateSubscriptionOwnerWallet to set up the wallet.Already Revoked
Already Revoked
If a subscription is already revoked, calling
revoke() again may fail. Check status first using getSubscriptionStatus.Important Notes
Permanent Action: Revoking a subscription is permanent and cannot be undone. The user would need to create a new subscription to re-enable charging.
User-Initiated Revocation: Users can also revoke subscriptions themselves from their wallet. Your backend should handle subscription status checks before attempting charges.
When to Use Revoke
Userevoke() from your backend when you need to programmatically cancel subscriptions:
- User requests cancellation through your application
- Policy violations or terms of service breaches
- Failed payments after multiple retry attempts
- Account closure or service termination
- Trial period expiration without conversion
- Administrative actions or bulk operations