0
Example:
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- This function creates a new wallet or retrieves an existing one
- The wallet is stored securely and associated with your CDP API credentials
- This is the wallet that will receive subscription payments
- Save the wallet address for use in the subscribe function
- Optional: use walletName parameter to create a custom-named wallet
Output
Click "Execute Code" to run your code
1
Pass Wallet to Frontend
Send wallet address from backend to frontend
Waiting for wallet address...
Example:
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- Get testnet USDC at https://faucet.circle.com/ - select "Base Sepolia"
- subscriptionOwner is your application's address that will control the subscription
- recurringCharge is the amount of USDC to charge per period (e.g., "10.50" = $10.50)
- Optional: use overridePeriodInSecondsForTestnet (testnet only) for fast testing (e.g., 10 = 10 second period)
- Optional: set requireBalance: false to skip balance check
Output
Click "Execute Code" to run your code
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- Use the subscription ID returned from the subscribe function
- remainingChargeInPeriod shows how much can still be charged this period
- Make sure to use the same testnet setting as the original subscription
Output
Click "Execute Code" to run your code
4
Pass Subscription ID to Backend
Send subscription ID from frontend to backend
Waiting for subscription ID...
Example:
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- The charge amount must be less than or equal to the recurringCharge
- You can only charge up to the remainingChargeInPeriod
- Charges can be made multiple times within a period up to the total recurring charge
- Use "max-remaining-charge" to charge the maximum remaining amount
- Optional: specify a recipient address to receive the USDC
Output
Click "Execute Code" to run your code
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- Same function as frontend, but typically called from your backend
- Use this to verify subscription status before granting access
- Check isSubscribed and remainingChargeInPeriod fields
Output
Click "Execute Code" to run your code
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- Once revoked, no more charges can be made
- The subscription payer can also revoke from their wallet
Output
Click "Execute Code" to run your code
š”
Automatic Recurring Charges (Cron Pattern)
Example pattern for automatically collecting charges each period
Code Editor
Intended for testing purposes only. Never paste code from untrusted sources.
Quick Tips
- This demo executes automatically and shows real-time output for each charging cycle
- By default, runs for 3 cycles - set maxCycles to null for continuous operation
- Each cycle checks subscription status, waits for the next period, then charges
- In production, use a proper scheduler like node-cron, bull queue, or cloud-based schedulers
- Store subscription IDs in a database and iterate through active subscriptions
- Use "max-remaining-charge" to collect the full recurring amount each period
Output
Click "Execute Code" to run your code