sub2
  • sub2 protocol
  • Concepts
    • Subscription
    • Fees
    • Fee auction
    • Sponsored subscriptions
    • Processors
  • Deployments
  • SDK
    • Query subscriptions
    • Listen for incoming subscriptions
    • Listen for canceled subscriptions
    • Listen for incoming payments
    • Sponsor subscriptions
    • Check if user is a payed subscriber
    • Cancel subscription
    • Process payments
    • Query active subscriptions to recipient
    • Query active subscriptions from sender
  • Popup integration
  • Become a payment processor
  • Technical Reference
  • DAO
Powered by GitBook
On this page
  1. SDK

Listen for canceled subscriptions

PreviousListen for incoming subscriptionsNextListen for incoming payments

Last updated 11 months ago

Similar to how we can use the sub2 SDK to listen to new subscriptions for a given recipient, we can also listen to canceled subscriptions. It is assumed that sub2-sdk is installed and setup as done .

const unwatch: WatchEventReturnType = sub2SDK.watchCanceledSubscriptions(recipientAddress, callbackFn);

Here recipientAddress is of type `0x{string}` and callbackFn is of type (subscriptionIndex: bigint) => any. The callback function is defined by you and is what is called on newly observed canceled subscriptions. For example, you can make a callback function which checks that the subscription index corresponds to an active subscription in your backend and update access accordingly.

The returned value unwatch of the viem type WatchEventReturnType is a function that can be called to stop listening for events.

here