Purpose
Solana token accounts can approve another authority to move tokens, but each token account can only have one approved authority at a time. That makes it hard for one wallet to safely support several spending arrangements for the same token, such as a monthly subscription, a fixed spending allowance, and a merchant billing agreement. This program solves that by giving each(user, token mint) pair a
program-controlled Subscription Authority. The user’s token account approves
that authority once. The program then checks each requested transfer against a
separate record that defines who can pull funds, how much they can pull, and
when the authorization expires or resets.
The Subscription Authority cannot move funds by itself. A transfer only succeeds
when it matches one of the user’s active authorizations.
To put an HTTP API behind a subscription plan with a command-line gateway, see
the Pay.sh guide.
Program ID
program/src/lib.rs. Local Surfpool workflows
install the program at this canonical address.
Set Up A Local Environment
The guides in this section build on a few shared values: a user who pays, a delegatee or merchant who collects, a token mint, and funded token accounts. This setup creates them on a local network, so you can run every snippet without real funds. Create a project and install the TypeScript SDK with the@solana/kit
versions it supports. "type": "module" lets the scripts use top-level
await:
surfnet_setTokenAccount
RPC method writes a token account with any balance, so you don’t need a faucet
or a mint authority. Save this as setup.ts:
setup.ts
setup.ts, such as fixed.ts. Start
the file with this import. It runs setup.ts first, so every run starts with
new funded wallets:
| In the guide | Use |
|---|---|
TOKEN_MINT_ADDRESS_HERE | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v (USDC) |
address('DELEGATEE_WALLET_ADDRESS_HERE'), address('PULLER_WALLET_ADDRESS_HERE'), address('NEW_PULLER_WALLET_ADDRESS_HERE') | delegateeSigner.address |
address('RECEIVER_TOKEN_ACCOUNT_ADDRESS_HERE'), address('MERCHANT_TOKEN_ACCOUNT_ADDRESS_HERE') | merchantTokenAccount |
merchantOrPullerSigner | merchantSigner |
npx tsx fixed.ts. Start with
Create Subscription Authority.
Close Subscription Authority
closes an authority that another guide created. Add its snippets to the end of
that guide’s file, drop their client, tokenMint, and
subscriptionAuthorityPda declarations, which the file already has, and leave
out receiver, because no sponsor funded the authority.
Delegation Models
The program supports three authorization models:| Model | Purpose |
|---|---|
| Fixed delegation | Let another wallet or service spend up to a fixed total amount, optionally until an expiry time. |
| Recurring delegation | Let another wallet or service spend up to a limit that resets every period, such as daily, weekly, or monthly. |
| Subscription plan | Let a merchant publish billing terms that users can accept, then allow approved collectors to charge subscribers each billing period. |
Supported Tokens
Supports all mints from both SPL Token and Token-2022. For Token-2022 mints with a configuredTransferHook, the program forwards the
mint’s hook accounts (hook program, ExtraAccountMetaList PDA, extras) into the
TransferChecked CPI on each delegated transfer, so the hook policy is
enforced. The SDK resolves them for you:
- Plugin client (
transferFixed,transferRecurring,transferSubscription) — appended automatically. - Building manually — call
resolveTransferHookAccounts, passtransferHookAccounts.
Onchain Events
The program emits onchain events via self-CPI so indexers and applications can track activity. All events are registered in the published IDL, so generated clients can decode them. The emitted events are:FixedTransferEvent,RecurringTransferEvent, andSubscriptionTransferEvent— one per delegated transfer. Each carries the creditedreceiverTokenAccount;SubscriptionTransferEventalso carries thepuller.SubscriptionCreatedEvent,SubscriptionCancelledEvent, andSubscriptionResumedEvent— subscription lifecycle.SubscriptionCreatedEventcarries thepayer. Dual-signed immediate cancellations also emitSubscriptionCancelledEvent, withexpiresAtTsset to the cancellation time instead of the end of the billing period.PlanUpdatedEvent— emitted when a plan is updated.
Versioning
Program-owned records include a version field. This gives the program a path to upgrade account data over time without breaking existing users. The migration strategy supports:- Lazy in-place update
- Explicit migrate instruction
- Revoke and recreate fallback
Contributors
The project is maintained by contributors to thesolana-program/subscriptions repository.
Audit Status
The program has been audited by Cantina. Audit status, baseline commit, fix-verified commit, and current unaudited delta are tracked in the repository’saudits/ directory.