The
subscribe function creates recurring USDC subscriptions using spend permissions on the Base network. This enables you to charge users periodically without requiring approval for each transaction. No fees for merchants or users.Parameters
Amount of USDC to charge per period (e.g., “10.50”). Maximum 6 decimal places.
Ethereum address that will be the spender (your application’s address).Pattern:
^0x[0-9a-fA-F]{40}$The period in days for the subscription (e.g., 30 for monthly). Default: 30
Set to true to use Base Sepolia testnet instead of mainnet. Default: false
Check if the payer’s wallet has sufficient USDC balance before creating the subscription. If true, subscription creation will fail if the payer doesn’t have enough balance to cover the recurring charge. Default: true
Whether to enable telemetry logging. Default: true
Returns
Subscription details on success. The function throws an error on failure.
Errors
Thesubscribe function throws an error when subscription creation fails. The error object contains a message explaining what went wrong.
Error Handling
Always wrap calls tosubscribe in a try-catch block: