Skip to main content
The VowenaClient is the primary interface for interacting with the Vowena smart contract. Write methods return an assembled XDR string for wallet signing. Read methods query on-chain state directly.
import { VowenaClient, NETWORKS } from "vowena";

const client = new VowenaClient({
  contractId: NETWORKS.testnet.contractId,
  rpcUrl: NETWORKS.testnet.rpcUrl,
  networkPassphrase: NETWORKS.testnet.networkPassphrase,
});

Write methods build and simulate a Soroban transaction, returning an assembled XDR string. You sign the XDR with your wallet and then call submitTransaction() to broadcast it.

buildCreatePlan

Creates a new subscription plan on-chain.
const xdr = await client.buildCreatePlan({
  merchant: "GMERCHANT...ADDR",
  token: NETWORKS.testnet.usdcAddress,
  amount: toStroops("9.99"),
  period: 2_592_000,
  priceCeiling: toStroops("14.99"),
  trialPeriods: 1,
  maxPeriods: 0,
  gracePeriod: 259_200,
});
ParameterTypeRequiredDescription
merchantstringYesStellar address of the merchant receiving payments
tokenstringYesToken contract address (e.g., USDC)
amountbigintYesAmount per billing period in stroops
periodnumberYesBilling period duration in seconds
priceCeilingbigintYesMaximum amount the plan can ever charge per period
trialPeriodsnumberNoNumber of free billing periods (default: 0)
maxPeriodsnumberNoMaximum billing periods, 0 = unlimited (default: 0)
gracePeriodnumberNoGrace period in seconds for failed charges (default: 2592000)
Returns: Promise<string> - Assembled XDR transaction string.

buildSubscribe

Subscribes a user to a plan. This also sets the SEP-41 token allowance in a single transaction.
const xdr = await client.buildSubscribe(
  "GSUBSCRIBER...ADDR",
  42
);
ParameterTypeRequiredDescription
subscriberstringYesStellar address of the subscriber
planIdnumberYesID of the plan to subscribe to
Returns: Promise<string> - Assembled XDR transaction string.

buildCharge

Charges a subscription for the current billing period. This is permissionless - anyone can call it.
const xdr = await client.buildCharge(
  "GCALLER...ADDR",
  101
);
ParameterTypeRequiredDescription
callerAddressstringYesStellar address of the caller (pays the tx fee)
subIdnumberYesSubscription ID to charge
Returns: Promise<string> - Assembled XDR transaction string.

buildCancel

Cancels a subscription. Can be called by either the subscriber or the merchant.
const xdr = await client.buildCancel(
  "GSUBSCRIBER...ADDR",
  101
);
ParameterTypeRequiredDescription
callerstringYesStellar address of the subscriber or merchant
subIdnumberYesSubscription ID to cancel
Returns: Promise<string> - Assembled XDR transaction string.

buildRefund

Issues a refund from the merchant to the subscriber.
const xdr = await client.buildRefund(
  "GMERCHANT...ADDR",
  101,
  toStroops("9.99")
);
ParameterTypeRequiredDescription
merchantAddressstringYesStellar address of the merchant issuing the refund
subIdnumberYesSubscription ID to refund
amountbigintYesRefund amount in stroops
Returns: Promise<string> - Assembled XDR transaction string.

buildUpdatePlanAmount

Updates the billing amount for an existing plan. The new amount must not exceed the plan’s price ceiling.
const xdr = await client.buildUpdatePlanAmount(
  "GMERCHANT...ADDR",
  42,
  toStroops("12.99")
);
ParameterTypeRequiredDescription
merchantAddressstringYesStellar address of the plan’s merchant
planIdnumberYesPlan ID to update
newAmountbigintYesNew amount per period in stroops
Returns: Promise<string> - Assembled XDR transaction string.
The new amount cannot exceed the plan’s priceCeiling. This protects subscribers from unexpected price increases beyond what they originally authorized.

buildRequestMigration

Requests migration of all subscribers from one plan to another. Subscribers must accept individually.
const xdr = await client.buildRequestMigration(
  "GMERCHANT...ADDR",
  42,  // old plan ID
  43   // new plan ID
);
ParameterTypeRequiredDescription
merchantstringYesStellar address of the merchant
oldPlanIdnumberYesPlan ID to migrate from
newPlanIdnumberYesPlan ID to migrate to
Returns: Promise<string> - Assembled XDR transaction string.

buildAcceptMigration

Accepts a pending migration for a subscription. Called by the subscriber.
const xdr = await client.buildAcceptMigration(
  "GSUBSCRIBER...ADDR",
  101
);
ParameterTypeRequiredDescription
subscriberstringYesStellar address of the subscriber
subIdnumberYesSubscription ID to migrate
Returns: Promise<string> - Assembled XDR transaction string.

buildRejectMigration

Rejects a pending migration for a subscription. Called by the subscriber.
const xdr = await client.buildRejectMigration(
  "GSUBSCRIBER...ADDR",
  101
);
ParameterTypeRequiredDescription
subscriberstringYesStellar address of the subscriber
subIdnumberYesSubscription ID whose migration to reject
Returns: Promise<string> - Assembled XDR transaction string.

buildReactivate

Reactivates a paused subscription. Called by the subscriber.
const xdr = await client.buildReactivate(
  "GSUBSCRIBER...ADDR",
  101
);
ParameterTypeRequiredDescription
subscriberstringYesStellar address of the subscriber
subIdnumberYesSubscription ID to reactivate
Returns: Promise<string> - Assembled XDR transaction string.