import { base } from '@base-org/account/node';// Requires: CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET env varsconst result = await base.subscription.charge({ id: '0x71319cd488f8e4f24687711ec5c95d9e0c1bacbf5c1064942937eba4c7cf2984', amount: '9.99'});console.log(`Charged subscription: ${result.id}`);console.log(`Amount: ${result.amount}`);
import { base } from '@base-org/account/node';const result = await base.subscription.charge({ id: '0x71319cd488f8e4f24687711ec5c95d9e0c1bacbf5c1064942937eba4c7cf2984', amount: '9.99', cdpApiKeyId: 'your-api-key-id', cdpApiKeySecret: 'your-api-key-secret', cdpWalletSecret: 'your-wallet-secret', testnet: false});console.log(`Charged subscription: ${result.id}`);
import { base } from '@base-org/account/node';// Charge the full remaining amount in current periodconst result = await base.subscription.charge({ id: subscriptionId, amount: 'max-remaining-charge', testnet: false});console.log(`Charged max remaining: ${result.amount}`);
import { base } from '@base-org/account/node';// Charge and transfer USDC to a specific recipientconst result = await base.subscription.charge({ id: subscriptionId, amount: '10.00', recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8', testnet: false});console.log(`Charged and sent to ${result.recipient}`);
import { base } from '@base-org/account/node';// Use a paymaster to sponsor gas feesconst result = await base.subscription.charge({ id: subscriptionId, amount: '15.00', paymasterUrl: 'https://api.developer.coinbase.com/rpc/v1/base/your-key', testnet: false});console.log(`Gasless charge: ${result.id}`);
import { base } from '@base-org/account/node';// Only needed if you used a custom name in getOrCreateSubscriptionOwnerWallet()const result = await base.subscription.charge({ id: subscriptionId, amount: '5.00', walletName: 'premium-subscriptions-wallet', // Must match wallet creation testnet: false});
Node.js Only: This function uses CDP (Coinbase Developer Platform) server wallets and is only available in Node.js environments. For browser/client-side applications, use prepareCharge instead.
The charge function executes subscription charges automatically from your backend. It uses a CDP smart wallet as the subscription owner, handling all transaction details including wallet management, transaction signing, and optional gas sponsorship. No manual transaction management required.
Optional custom wallet name for the CDP smart wallet. Default: “subscription owner”
Use Default: Most applications should omit this parameter and use the default. Only specify if you used a custom name in getOrCreateSubscriptionOwnerWallet().
Or pass directly as parameters (see examples below).
import { base } from '@base-org/account/node';// Requires: CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET env varsconst result = await base.subscription.charge({ id: '0x71319cd488f8e4f24687711ec5c95d9e0c1bacbf5c1064942937eba4c7cf2984', amount: '9.99'});console.log(`Charged subscription: ${result.id}`);console.log(`Amount: ${result.amount}`);
import { base } from '@base-org/account/node';const result = await base.subscription.charge({ id: '0x71319cd488f8e4f24687711ec5c95d9e0c1bacbf5c1064942937eba4c7cf2984', amount: '9.99', cdpApiKeyId: 'your-api-key-id', cdpApiKeySecret: 'your-api-key-secret', cdpWalletSecret: 'your-wallet-secret', testnet: false});console.log(`Charged subscription: ${result.id}`);
import { base } from '@base-org/account/node';// Charge the full remaining amount in current periodconst result = await base.subscription.charge({ id: subscriptionId, amount: 'max-remaining-charge', testnet: false});console.log(`Charged max remaining: ${result.amount}`);
import { base } from '@base-org/account/node';// Charge and transfer USDC to a specific recipientconst result = await base.subscription.charge({ id: subscriptionId, amount: '10.00', recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8', testnet: false});console.log(`Charged and sent to ${result.recipient}`);
import { base } from '@base-org/account/node';// Use a paymaster to sponsor gas feesconst result = await base.subscription.charge({ id: subscriptionId, amount: '15.00', paymasterUrl: 'https://api.developer.coinbase.com/rpc/v1/base/your-key', testnet: false});console.log(`Gasless charge: ${result.id}`);
import { base } from '@base-org/account/node';// Only needed if you used a custom name in getOrCreateSubscriptionOwnerWallet()const result = await base.subscription.charge({ id: subscriptionId, amount: '5.00', walletName: 'premium-subscriptions-wallet', // Must match wallet creation testnet: false});