Skip to content
A recurring delegation lets a user approve another wallet or service to pull up to a limit that resets every period. This guide keeps the moving parts visible. You derive the accounts first, initialize the Subscription Authority if needed, create the recurring delegation, then use that delegation PDA for transfers. To run these snippets on a local network, first set up a local environment.

​Install

​Create The Delegation

The setup has four parts:
  1. Create a client with the user signer and subscriptions plugin.
  2. Derive the user’s token account, Subscription Authority PDA, and recurring delegation PDA.
  3. Initialize the Subscription Authority if it does not exist yet.
  4. Create the recurring delegation with the period amount, period length, start time, and expiry.

​Transfer From The Delegation

The delegatee signs each transfer. The program checks the current period and rejects transfers that would exceed the period’s remaining allowance.

​Revoke The Delegation

The delegator can revoke the recurring delegation at any time. Revoking closes the delegation PDA and returns its rent to the signer.

​Notes

  • amountPerPeriod is in base units. For a 6-decimal token, 1_000_000 means 1 token.
  • The program rejects transfers that exceed the current period’s remaining allowance.
  • Once the next period starts, the pulled amount resets.
  • expiryTs is a hard stop: once it passes, transfers fail and the sponsor can recover rent. There is no spend-time grace period.
  • The examples use startTs = 0n (start_ts = 0 in Rust), so the delegation starts when the transaction lands. A fixed startTs in the past fails with RecurringDelegationStartTimeInPast. On a local Surfpool the cluster clock can lag your wall clock, so a startTs of “now” may still be in the future for the program, and a transfer right after creation fails with DelegationNotStarted (error 407). Either keep startTs at 0, or advance the clock first with the surfnet_timeTravel RPC method, passing absoluteTimestamp set to the current time.
  • Set startTs to 0 to start the delegation when the transaction lands on chain instead of at a fixed time. This widens the window to get the user to sign and onboard. When you do this, expiryTs must be non-zero — a start-on-landing delegation cannot also be set to never expire.
  • The user signs setup and revoke transactions. The delegatee signs transfers.