Recur Docs

Subscribe

Build subscribe transactions and manage USDC delegation for recurring payments.

Subscribe

buildSubscribeTransaction

Builds the instructions to create an on-chain subscription. Returns the PDA, instructions, and bump seed — you handle signing and sending.

import { RecurClient, getClusterDefaults } from "@recur/sdk";
import { Transaction, Connection } from "@solana/web3.js";
 
const recur = new RecurClient({
  rpcUrl: "https://api.devnet.solana.com",
  apiBaseUrl: "https://api.recur.so",
});
 
const { subscriptionPda, instructions, bump } = recur.buildSubscribeTransaction(
  wallet.publicKey,
  {
    planId: "plan_abc123",
    merchantWallet: "MERCHANTxxx...",
    planSeed: "0100000000000000", // hex, 16 chars (8 bytes)
    amount: 5_000_000,            // $5.00 USDC (6 decimals)
    intervalSeconds: 2_592_000,   // 30 days
    delegationCycles: 12,         // optional, default 12
  },
);
 
const tx = new Transaction().add(...instructions);
const signed = await wallet.signTransaction(tx);
const sig = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(sig, "confirmed");

Instructions generated

  1. SPL Token approve — delegates amount × delegationCycles USDC to the Subscription PDA
  2. initialize_subscription — creates the on-chain PDA with amount, interval, and plan seed

Parameters

FieldTypeDescription
planIdstringPlan identifier from the Recur API
merchantWalletstringMerchant's Solana wallet address
planSeedstringHex-encoded 8-byte plan seed (16 chars)
amountnumberPayment amount in USDC base units (6 decimals)
intervalSecondsnumberBilling interval in seconds
delegationCyclesnumberNumber of payments to pre-approve. Default 12

subscribe (high-level)

Full end-to-end flow: build → sign → confirm → register with API.

const token = await recur.authenticate(wallet);
 
const { subscriptionPda, signature, subscription } = await recur.subscribe(
  wallet,
  {
    appId: "app_xxx",
    planId: "plan_abc123",
    merchantWallet: "MERCHANTxxx...",
    planSeed: "0100000000000000",
    amount: 5_000_000,
    intervalSeconds: 2_592_000,
    delegationCycles: 12,
  },
  token,
);

After the transaction confirms, subscribe calls registerSubscription automatically so the keeper and API are aware of the subscription.

Re-approving an exhausted delegation

When the SPL Token delegation is used up (after delegationCycles payments) or if the subscriber manually revoked it, re-approve without touching subscription state.

buildReapproveTransaction

const { subscriptionPda, instructions } = recur.buildReapproveTransaction(
  wallet.publicKey,
  {
    merchantWallet: "MERCHANTxxx...",
    planSeed: "0100000000000000",
    amount: 5_000_000,
    delegationCycles: 24,
  },
);
 
const tx = new Transaction().add(...instructions);
const signed = await wallet.signTransaction(tx);
await connection.sendRawTransaction(signed.serialize());

reapprove (high-level)

await recur.reapprove(wallet, {
  merchantWallet: "MERCHANTxxx...",
  planSeed: "0100000000000000",
  amount: 5_000_000,
  delegationCycles: 24,
});

Signs, sends, and confirms the re-approval transaction in one call.

Helper: signAndSend

For manual flows you can use the exported helper:

import { signAndSend } from "@recur/sdk";
 
const signature = await signAndSend(connection, wallet, instructions);

On this page