Server-side helpers
Drive subscriptions from a backend or Node script using RecurClient.
Server-side helpers
The same high-level operations available in the browser are exposed directly on RecurClient. Use these from a Node service, an API route, a test fixture, or a custom signing flow.
All methods take a RecurWallet (anything with publicKey, signTransaction, and signMessage). A keypair on the server can implement this interface directly; a browser passes the wallet adapter.
client.authenticate(wallet)
Runs nonce → signMessage → verify against /auth/verify and returns a JWT string.
client.subscribe(wallet, options, token)
Builds the approve + initialize_subscription transaction, signs and confirms it, then registers the new subscription with the Recur API. Returns the on-chain PDA, the transaction signature, and the registered SubscriptionInfo.
client.cancel(wallet, options)
"request"→request_cancelinstruction (prepaid period honored)"instant"→subscriber_cancelinstruction (immediate close)
client.reapprove(wallet, options)
Re-runs spl-token approve for the existing subscription PDA so the keeper can pull again.
Errors
Every method throws a typed subclass of RecurError:
| Error | When |
|---|---|
WalletRejectedError | User declined the prompt |
InsufficientFundsError | Subscriber's USDC balance can't cover the next payment |
DelegationExhaustedError | Approval used up — call reapprove() |
PlanInactiveError | Plan was disabled by the merchant |
SubscriptionAlreadyExistsError | Subscriber already has an active sub on this plan |
NetworkError | RPC or API unreachable |
AuthError | JWT invalid/expired |
Check with instanceof. See the full error reference.