Skip to content
LogoLogo

Method.tempo.renewSubscription

Renew subscriptions outside requests

Renews an overdue Tempo subscription from a background worker or cron job.

Usage

import { ,  } from 'mppx/server'
 
const  = .()
 
const  = await .({
  ,
  : 'sub_abc123',
})
 
.(?..)
success

The function returns null when the subscription is already current.

With custom renewal

Pass renew when your application owns settlement.

import { ,  } from 'mppx/server'
 
const  = .()
 
const  = await .({
  : async ({ , ,  }) => {
    const  = new ().()
    return {
      : {
        : 'tempo',
        : '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
        : 'success',
        : .,
        ,
      },
      : {
        ...,
        ,
        : ,
        : '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
        ,
      },
    }
  },
  ,
  : 'sub_abc123',
})

Return type

type ReturnType = Promise<
  | {
      receipt: SubscriptionReceipt
      subscription: SubscriptionRecord
    }
  | null
>

Parameters

getClient (optional)

  • Type: (parameters: { chainId?: number }) => MaybePromise<Client>

Function that returns a viem client for the subscription's Tempo chain ID.

renew (optional)

  • Type: (parameters: { inFlightReference: string; periodIndex: number; subscription: SubscriptionRecord }) => Promise<RenewalResult>

Custom renewal hook. The inFlightReference is stable for the subscription period and works as an idempotency key.

renewalTimeoutMs (optional)

  • Type: number
  • Default: 900000

Milliseconds before an in-flight renewal lock can be replaced.

store

  • Type: Store.AtomicStore<Record<string, unknown>>

Atomic store containing subscription records.

subscriptionId

  • Type: string

Subscription to renew.

waitForConfirmation (optional)

  • Type: boolean

Whether to wait for the renewal transfer to confirm before returning a Receipt.