An interactive playground for exploring Base subscription functionality with split-screen frontend and backend controls.
- Frontend Section (Left/Top): Client-side subscription functions
- Backend Section (Right/Bottom): Server-side subscription management
-
base.subscription.subscribe
- Create recurring USDC subscriptions on Base
- Configure subscription owner, amount, and period
- Testnet support
-
base.subscription.getStatus
- Check subscription status
- View remaining charge in period
- See next billing date
-
base.subscription.charge
- Charge a subscription for the current period
- Specify custom charge amounts
- Uses CDP wallet (server-side with API credentials)
- Optional recipient address for USDC transfer
-
base.subscription.getStatus
- Same as frontend, but for backend verification
- Check subscription validity before processing
-
base.subscription.revoke
- Cancel/revoke a subscription
- Owner-controlled revocation (uses CDP wallet credentials)
- Prevents future charges
- Server-side only operation
- Pass Subscription Owner Wallet to Frontend: Automatically updates frontend subscribe code with wallet address
- Pass Subscription ID to Backend: Automatically populates backend functions with subscription ID from frontend
- Live code editing with syntax highlighting
- Real-time execution with mock Base SDK
- Console output capture
- Error handling and display
- Code sanitization for security
- Clean, modern UI inspired by the Base testapp
- Responsive design
- Color-coded sections (Frontend: Yellow, Backend: Blue)
- Interactive code editors with tips
yarn installyarn devOpen http://localhost:3000 to view the playground.
yarn build
yarn start- Next.js: React framework
- TypeScript: Type safety
- CSS Modules: Scoped styling
- Acorn: JavaScript parsing and validation
- @base-org/account: Base subscription SDK (real implementation)
- Code sanitization and validation using AST parsing
- Whitelist-based function execution
- No access to dangerous globals
- Import/export stripping
- Console output capture
This playground combines concepts from:
/Users/spencerstock/src/cdp-wallet-subscription-demo: Backend/Frontend integration patterns/Users/spencerstock/src/account-sdk/examples/testapp: Code editor styling and execution
-
Enter Subscription Owner Wallet
- Input your wallet address in the control panel
- Click "Pass to Frontend →" to auto-fill the subscribe function
-
Create a Subscription (Frontend)
- Edit the subscription parameters (amount, period)
- Click "Execute Code" to create subscription
- Note the generated subscription ID
-
Pass Subscription ID to Backend
- Click "Pass to Backend ←" to auto-fill backend functions
- This enables charging, status checks, and revocation
-
Charge Subscription (Backend)
- Specify charge amount (must be ≤ recurringCharge)
- Execute to charge the subscription
- View transaction details
-
Check Status (Either Side)
- Execute getStatus to view subscription details
- See remaining charge in period
- Check subscription active status
-
Revoke Subscription (Backend)
- Execute revoke to cancel subscription
- No more charges can be made after revocation
- Get testnet USDC at https://faucet.circle.com/ (Base Sepolia)
- subscriptionOwner is your app's address
- recurringCharge is in USDC (e.g., "10.50")
- Users can revoke anytime from their wallet
- Amount must be ≤ recurringCharge
- Can only charge up to remainingChargeInPeriod
- Uses CDP wallet credentials (server-side only)
- Multiple charges allowed per period
- Optional recipient parameter to send USDC to a different address
- Only subscription owner can revoke (via CDP wallet credentials)
- Uses CDP wallet (server-side with API credentials)
- Once revoked, subscription is permanently cancelled
- Payer can also revoke from their wallet directly
To use real Base SDK functionality, you need to configure CDP API credentials:
-
Get CDP API Keys
- Sign up at https://portal.cdp.coinbase.com/
- Create API keys from the dashboard
- Note your API Key ID and Secret
-
Create Environment File
- Copy
.env.exampleto.env.local - Fill in your CDP credentials:
CDP_API_KEY_ID=your_api_key_id CDP_API_KEY_SECRET=your_api_key_secret CDP_WALLET_SECRET=your_secure_random_string - Generate a secure random string for
CDP_WALLET_SECRET
- Copy
-
Restart Development Server
yarn dev
The playground now uses the real @base-org/account SDK with:
- Client-side functions:
subscribe,getStatus - Server-side functions:
charge,revoke,getOrCreateSubscriptionOwnerWallet
MIT