Node.js Only: This function uses CDP (Coinbase Developer Platform) and is only available in Node.js environments.
How It Works
This function:- Initializes a CDP client with your credentials
- Creates or retrieves an EOA (Externally Owned Account) with the specified name
- Creates or retrieves a smart wallet owned by that EOA
- Returns the smart wallet address (not the EOA address)
subscriptionOwner parameter when calling subscribe().
Parameters
CDP 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 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
Wallet creation result.
Setup
Get CDP credentials from the CDP Portal. Set as environment variables:Idempotency
This function is idempotent: Calling it multiple times with the samewalletName returns the same wallet.
Error Handling
Common Errors
Missing CDP Credentials
Missing CDP Credentials
CDP_API_KEY_IDCDP_API_KEY_SECRETCDP_WALLET_SECRET
Invalid Credentials
Invalid Credentials
Smart Wallet Benefits
Using a CDP smart wallet as your subscription owner provides several advantages:Automatic Transaction Management
Automatic Transaction Management
The smart wallet handles all transaction details including nonce management, gas estimation, and retries.
Gas Sponsorship
Gas Sponsorship
Smart wallets support paymasters, allowing you to sponsor gas fees for subscription charges and revocations.
Batched Transactions
Batched Transactions
Smart wallets can batch multiple operations into a single transaction, reducing gas costs and improving efficiency.
Secure Key Management
Secure Key Management
CDP manages the private keys securely, reducing the risk of key compromise in your application.
Best Practices
- Use Environment Variables
- One-Time Setup
- Advanced: Multiple Wallets
Store CDP credentials as environment variables instead of hardcoding them:Then use them:
.env
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 on-chain. This is expected and safe - users need to know which address they’re granting permissions to.