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

Sponsor subscriptions

PreviousListen for incoming paymentsNextCheck if user is a payed subscriber

Last updated 12 months ago

The sub2 SDK can be used to generate EIP-712 signatures used for sponsoring new subscriptions. As mentioned , sponsoring a subscription means that all processing fees are paid by you.

This feature requires that the Sub2SDK class is initialized with a private key.

To sponsor a subscription, we first have to specify the details of the subscription we wish to sponsor. This is done by creating a SponsorPermit object which can be imported directly from sub2-sdk:

interface SponsorPermit {
  nonce: bigint,
  deadline: bigint,
  recipient: `0x${string}`,
  amount: bigint,
  token: `0x${string}`,
  cooldown: number,
  delay: number,
  auctionDuration: number,
  initialPayments: number,
  maxProcessingFee: bigint,
  processingFeeToken: `0x${string}`
}

The nonce an uint256 value which cannot be used by a signature previously. In practice this can be set to a random uint256 value as the chance of collision is infinitely small. The deadline is the UNIX time in seconds when the signature will expire. After this time, the signature will no longer be valid.

Once we have a sponsor permit, we can use the SDK to generate a signature:

const signature: `0x${string}` = await sub2SDK.generateSponsorSignature(sponsorPermit);

Now we have a signature which you can use to sponsor a subscription!

Reminder: The signature is only valid for a subscription created with the exact details you specified in the SponsorPermit object! Furthermore, the signature can only be used once.

here