Subscription Methods

Subscription methods of Papaya SDK for managing subscriptions to content creators

subscribe()

Creates a new subscription to a creator.

async subscribe(
  author: string, 
  amount: number | bigint,
  period: RatePeriod = RatePeriod.MONTH,
  projectId: number
): Promise<ethers.TransactionResponse>

Parameters:

  • author: The address of the creator to subscribe to

  • amount: The amount of tokens for the subscription period

  • period: (Optional) The subscription period (default: RatePeriod.MONTH)

  • projectId: The project ID associated with the subscription

Returns: An ethers.js TransactionResponse object.

Example:

const creatorAddress = '0x...';
const tx = await papaya.subscribe(creatorAddress, 10, RatePeriod.MONTH, 0);
await tx.wait();

subscribeBySig()

Creates a subscription transaction that can be signed off-chain and executed by anyone.

Parameters:

  • author: The address of the creator to subscribe to

  • amount: The amount of tokens for the subscription period

  • period: (Optional) The subscription period (default: RatePeriod.MONTH)

  • projectId: The project ID associated with the subscription

  • deadline: Timestamp after which the transaction can't be executed

Returns: An ethers.js TransactionResponse object.

Example:

unsubscribe()

Cancels a subscription to a creator.

Parameters:

  • author: The address of the creator to unsubscribe from

Returns: An ethers.js TransactionResponse object.

Example:

unsubscribeBySig()

Creates an unsubscribe transaction that can be signed off-chain and executed by anyone.

Parameters:

  • author: The address of the creator to unsubscribe from

  • deadline: Timestamp after which the transaction can't be executed

Returns: An ethers.js TransactionResponse object.

Example:

getSubscriptions()

Gets all subscriptions for an account.

Parameters:

  • account: (Optional) The address to get subscriptions for. If not provided, uses the connected signer's address.

Returns: Array of Subscription objects, each containing:

  • recipient: The address receiving the subscription

  • incomeRate: The rate at which the recipient is receiving tokens (raw format)

  • outgoingRate: The rate at which the subscriber is paying tokens (raw format)

  • projectId: The project ID associated with the subscription

circle-info

The incomeRate and outgoingRate values are per-second rates in their raw blockchain format. You should use the utility functions to convert them to human-readable values.

Example:

Last updated