Node.js Only: This function uses CDP (Coinbase Developer Platform) and is only available in Node.js environments.
The getOrCreateSubscriptionOwnerWallet function creates or retrieves a CDP smart wallet that acts as the subscription owner (spender). This wallet is used by charge() and revoke() to manage subscriptions from your backend.
Optional custom wallet name for organization. Default: “subscription owner”
Default Recommended: Most applications should use the default wallet name. The default ensures consistency across all subscription operations automatically.
Custom Wallet Names: If you specify a custom walletName, you must use the exact same name in all subsequent charge() and revoke() calls. Mismatched names will cause operations to fail.
Call this function once during your application initialization, not on every request:
server.ts
Report incorrect code
Copy
Ask AI
let subscriptionOwnerAddress: string;async function initialize() { const wallet = await base.subscription.getOrCreateSubscriptionOwnerWallet(); subscriptionOwnerAddress = wallet.address; console.log(`Subscription owner: ${subscriptionOwnerAddress}`);}// Initialize once at startupinitialize().catch(console.error);
Only if you need separate wallets for different subscription tiers:
Report incorrect code
Copy
Ask AI
// ADVANCED: Most apps don't need this// Only use if you need to segregate funds by subscription type// Wallet for premium subscriptionsconst premiumWallet = await base.subscription.getOrCreateSubscriptionOwnerWallet({ walletName: 'premium-subscriptions'});// Wallet for basic subscriptionsconst basicWallet = await base.subscription.getOrCreateSubscriptionOwnerWallet({ walletName: 'basic-subscriptions'});// IMPORTANT: Remember to pass the same walletName to charge() and revoke()
Use environment variables or secret management systems
Rotate credentials periodically
Restrict CDP API key permissions to only what’s needed
Wallet Address is PublicThe smart wallet address is public and will be visible on-chain. This is expected and safe - users need to know which address they’re granting permissions to.