Write

Subs sdk write methods

Create Plan

Initialize Subs Client

import { SubsSDK, PaymentType, PeriodType, SubsPayment, Keypair } from 'subs-sdk';

// Initialize with wallet private key (keep this secure!)
const subsClient = new SubsSDK("YOUR_WALLET_PRIVATE_KEY", "testnet"); // "testnet" or "public"

Payment Configuration

// Get creator keypair
const creatorKeypair = Keypair.fromSecret("OWNER_SECRET_KEY");
const creatorAddress = creatorKeypair.publicKey();

// Configure payment type
const paymentType: PaymentType = {
  tag: "ERC20",      // Only ERC20 for the moment.
  values: undefined // For simple payment types
};

// Configure period type
const periodType: PeriodType = {
  tag: "DAYS", // Other options: ONETIME | MINUTES | HOURS | WEEK | MONTH | YEAR
  values: undefined
};

Payment Plans Setup

Execute Creation

Returns App Url

Payment Struct

1. name

  • Type: string

  • Description: Unique identifier for the payment plan (e.g., Student, Premium).

  • Rules:

    • Must be unique across all your payment plans.


2. owner

  • Type: string (Stellar public key)

  • Description: Revenue beneficiary address.

  • Default: Use your creatorAddress (if not specified).

  • Revenue Sharing:

    • If owner ≠ creatorAddress, fees are split:

      • owner earns fee%

      • creatorAddress earns 100% - fee%.


3. fee

  • Type: BigInt (basis points: 10 = 1%)

  • Description: Revenue share for owner (only if owner ≠ creatorAddress).

  • Example:


4. payment_type

  • Type: PaymentType

  • Options:

  • Future: May support NFTs or other assets via values.


5. payment_tokens

  • Type: Array<Token>

  • Structure:

  • Rules:

    • If the first_amount is set to 0 no change.

    • But you can customize the First payment more or less then the price

    • Use valid Stellar Token Address otherwise the payment won't work.

  • Example:


6. period_type

  • Type: PeriodType

  • Options:

  • Example:


7. trial_period

  • Type: BigInt

  • Description: Free trial duration (units depend on period_type):

    • DAYS, WEEK, MONTH, YEAR → Trial in days.

    • HOURS → Trial in hours.

    • MINUTES → Trial in minutes.

  • Example:


8. limit_period

  • Type: BigInt

  • Description: Number of billing cycles users must commit to.

  • Example:


9. loading_time

  • Type: BigInt

  • Description: Grace period (in days) for late payments before subscription deactivation.

  • Example:

Last updated