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

How It Works

This function:
  1. Initializes a CDP client with your credentials
  2. Creates or retrieves an EOA (Externally Owned Account) with the specified name
  3. Creates or retrieves a smart wallet owned by that EOA
  4. Returns the smart wallet address (not the EOA address)
Architecture:
The smart wallet address is what you use as the subscriptionOwner parameter when calling subscribe().

Parameters

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 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.

Returns

GetOrCreateSubscriptionOwnerWalletResult
Wallet creation result.

Setup

Get CDP credentials from the CDP Portal. Set as environment variables:
Or pass directly as parameters (see examples below).

Idempotency

This function is idempotent: Calling it multiple times with the same walletName returns the same wallet.

Error Handling

Common Errors

Solution: Ensure environment variables are set:
  • CDP_API_KEY_ID
  • CDP_API_KEY_SECRET
  • CDP_WALLET_SECRET
Or pass them as parameters to the function.Get credentials from CDP Portal.
Solution: Verify your CDP credentials are correct and active in the CDP Portal.

Smart Wallet Benefits

Using a CDP smart wallet as your subscription owner provides several advantages:
The smart wallet handles all transaction details including nonce management, gas estimation, and retries.
Smart wallets support paymasters, allowing you to sponsor gas fees for subscription charges and revocations.
Smart wallets can batch multiple operations into a single transaction, reducing gas costs and improving efficiency.
CDP manages the private keys securely, reducing the risk of key compromise in your application.

Best Practices

Store CDP credentials as environment variables instead of hardcoding them:
.env
Then use them:

Security Considerations

Keep CDP Credentials Secure
  • Never commit credentials to version control
  • 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 onchain. This is expected and safe - users need to know which address they’re granting permissions to.

Charge

Execute charges with this wallet

Revoke

Cancel subscriptions with this wallet

Subscribe

Use wallet address when subscribing