Skip to main content
Defined in the Base Account SDK
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 call revoke(), the function:
  1. Initializes a CDP client with your credentials
  2. Retrieves the existing smart wallet (subscription owner)
  3. Prepares the revoke transaction call
  4. Executes the revocation using the smart wallet
  5. Optionally uses a paymaster for gas sponsorship
  6. Returns the transaction hash

Parameters

string
required
The subscription ID (permission hash) returned from subscribe().Pattern: ^0x[0-9a-fA-F]{64}$
boolean
Whether to use Base Sepolia testnet. Must match the network used in subscribe(). Default: false
string
CDP API key ID. Falls back to CDP_API_KEY_ID environment variable.
string
CDP API key secret. Falls back to CDP_API_KEY_SECRET environment variable.
string
CDP wallet secret. Falls back to CDP_WALLET_SECRET environment variable.
string
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().
string
Paymaster URL for transaction sponsorship (gasless transactions). Falls back to PAYMASTER_URL environment variable.

Returns

RevokeResult
Revoke execution result.

Setup

Before using revoke(), you need CDP credentials. Get them from the CDP Portal. Set as environment variables:
Or pass directly as parameters (see examples below).

Error Handling

Always wrap revoke() calls in try-catch blocks:

Common Use Cases

Common Errors

Solution: Ensure CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET are set as environment variables or passed as parameters.
Solution: Check that the subscription ID is correct. The subscription may have already been revoked or never existed.
Solution: The CDP wallet hasn’t been created yet. First call getOrCreateSubscriptionOwnerWallet to set up the wallet.
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

Use revoke() 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

Setup Wallet

Create CDP wallet before revoking

Check Status

Verify subscription before revoking

Custom Revoke

Advanced manual execution