Skip to main content
Defined in the Base Account SDK
Most developers should use revoke() instead, which handles execution automatically using CDP wallets. This function is for advanced use cases requiring custom transaction handling.
The prepareRevoke function prepares the necessary transaction call to revoke a subscription. It returns call data that you can execute through your own wallet infrastructure using wallet_sendCalls or eth_sendTransaction.

When to Use This

Use prepareRevoke only if you need:
  • Custom wallet infrastructure (not using CDP)
  • Manual transaction control
  • Integration with existing wallet systems
For standard backend subscription management, use revoke() instead.

Parameters

id
string
required
The subscription ID (permission hash) returned from subscribe().Pattern: ^0x[0-9a-fA-F]{64}$
testnet
boolean
Must match the testnet setting used in the original subscribe call. Default: false

Returns

result
PrepareRevokeResult
Single transaction call to execute the revocation.
import { base } from '@base-org/account';
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base as baseChain } from 'viem/chains';

// Initialize wallet client with your subscription owner account
const account = privateKeyToAccount('0x...'); // Your app's private key
const walletClient = createWalletClient({
  account,
  chain: baseChain,
  transport: http()
});

// Prepare the revoke call
const revokeCall = await base.subscription.prepareRevoke({
  id: '0x71319cd488f8e4f24687711ec5c95d9e0c1bacbf5c1064942937eba4c7cf2984',
  testnet: false
});

// Execute the revoke transaction
const hash = await walletClient.sendTransaction({
  to: revokeCall.to,
  data: revokeCall.data,
  value: revokeCall.value
});

// Wait for confirmation
const receipt = await walletClient.waitForTransactionReceipt({ hash });

console.log(`Revoked subscription: ${receipt.transactionHash}`);
{
  to: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  data: "0x9c4ae2d0...",
  value: 0n
}

Error Handling

try {
  const revokeCall = await base.subscription.prepareRevoke({
    id: subscriptionId,
    testnet: false
  });
  
  // Execute revoke transaction
  const hash = await walletClient.sendTransaction({
    to: revokeCall.to,
    data: revokeCall.data,
    value: revokeCall.value
  });
  
  console.log(`Revoke transaction: ${hash}`);
  
} catch (error) {
  console.error(`Failed to prepare revoke: ${error.message}`);
}

Comparison with revoke()

  • Using prepareRevoke (Advanced)
// You manage everything manually
const revokeCall = await base.subscription.prepareRevoke({
  id: subscriptionId,
  testnet: false
});

// Initialize wallet client
const walletClient = createWalletClient({
  account: privateKeyToAccount('0x...'),
  chain: baseChain,
  transport: http()
});

// Execute transaction
const hash = await walletClient.sendTransaction({
  to: revokeCall.to,
  data: revokeCall.data,
  value: revokeCall.value
});

// Wait for confirmation
await walletClient.waitForTransactionReceipt({ hash });

// Handle gas estimation, nonce management, retries, etc.

Important Notes

Security: You must execute the revoke call from the subscription owner wallet. Executing from any other wallet will fail.
Network Matching: The testnet parameter must match the network used when creating the subscription with subscribe().

Common Errors

Subscription with ID 0x... not found
Solution: Verify the subscription ID is correct. The subscription may have already been revoked.
If you execute the transaction from a wallet that isn’t the subscription owner, the transaction will revert.Solution: Ensure you’re using the same wallet address that was specified as subscriptionOwner in the subscribe() call.
Using testnet: false for a subscription created on testnet (or vice versa) will cause errors.Solution: Match the testnet parameter to the network where the subscription was created.

Migration to revoke()

If you’re currently using prepareRevoke, consider migrating to revoke():
Before (prepareRevoke)
// Old approach - manual execution
const revokeCall = await base.subscription.prepareRevoke({
  id: subscriptionId,
  testnet: false
});

const walletClient = createWalletClient({
  account: privateKeyToAccount(process.env.PRIVATE_KEY),
  chain: baseChain,
  transport: http()
});

const hash = await walletClient.sendTransaction({
  to: revokeCall.to,
  data: revokeCall.data,
  value: revokeCall.value
});

await walletClient.waitForTransactionReceipt({ hash });
After (revoke)
// New approach - automatic execution with CDP
const result = await base.subscription.revoke({
  id: subscriptionId,
  testnet: false
});

console.log(`Revoked: ${result.id}`);