Verxio Protocol

Create Loyalty Program

Create a new loyalty program with custom tiers, rewards, and point configurations. This function initializes a new collection on the blockchain that will manage all loyalty passes for your program.

Overview

The createLoyaltyProgram function creates a new loyalty program as a Metaplex CORE collection. This collection will hold all loyalty passes issued for your program and define the tier structure, rewards, and point allocation rules.

Note: You can either provide a pre-uploaded metadata URI or provide an image buffer and filename to auto-upload the image and generate metadata.

Usage Examples

1. Using a Pre-uploaded Metadata URI

If you already have metadata uploaded to Arweave or another storage service:

import { createLoyaltyProgram } from '@verxioprotocol/core'
import { generateSigner } from '@metaplex-foundation/umi'

const result = await createLoyaltyProgram(context, {
  loyaltyProgramName: 'Coffee Brew Rewards',
  metadataUri: 'https://arweave.net/...', // Already uploaded metadata
  programAuthority: context.programAuthority,
  updateAuthority: generateSigner(context.umi), // Optional: Provide custom update authority
  metadata: {
    organizationName: 'Coffee Brew', // Required: Name of the host/organization
    brandColor: '#FF5733', // Optional: Brand color for UI customization
  },
  tiers: [
    {
      name: 'Bronze',
      xpRequired: 500,
      rewards: ['2% cashback'],
    },
    {
      name: 'Silver',
      xpRequired: 1000,
      rewards: ['5% cashback'],
    },
  ],
  pointsPerAction: {
    purchase: 100,
    review: 50,
  },
})

2. Uploading an Image and Generating Metadata

If you want the protocol to handle image upload and metadata generation:

import { createLoyaltyProgram } from '@verxioprotocol/core'
import { generateSigner } from '@metaplex-foundation/umi'
import fs from 'fs'

const imageBuffer = fs.readFileSync('logo.png')
const result = await createLoyaltyProgram(context, {
  loyaltyProgramName: 'Coffee Brew Rewards',
  imageBuffer, // Buffer of your image
  imageFilename: 'logo.png',
  programAuthority: context.programAuthority,
  updateAuthority: generateSigner(context.umi), // Optional: Provide custom update authority
  metadata: {
    organizationName: 'Coffee Brew', // Required: Name of the host/organization
    brandColor: '#FF5733', // Optional: Brand color for UI customization
  },
  tiers: [
    {
      name: 'Bronze',
      xpRequired: 500,
      rewards: ['2% cashback'],
    },
    {
      name: 'Silver',
      xpRequired: 1000,
      rewards: ['5% cashback'],
    },
  ],
  pointsPerAction: {
    purchase: 100,
    review: 50,
  },
})
// The protocol will upload the image, generate metadata, and use the resulting URI

Parameters

The function accepts a context object and a configuration object with the following parameters:

ParameterTypeRequiredDescription
contextVerxioContextThe initialized Verxio context object
loyaltyProgramNamestringDisplay name for your loyalty program
metadataUristringURI pointing to the program's metadata JSON (if not providing imageBuffer)
imageBufferBufferBuffer of your image file (if not providing metadataUri)
imageFilenamestringName of your image file (required if providing imageBuffer)
imageContentTypestringMIME type of your image (e.g., "image/png")
programAuthoritySignerThe authority that can manage this program
updateAuthoritySignerAuthority for program updates (optional)
metadata.organizationNamestringName of your organization
metadata.brandColorstringHex color code for UI customization
tiersArray<Tier>Array of tier definitions with names, XP requirements, and rewards
pointsPerActionRecord<string, number>Points awarded for different user actions

Tier Object Structure

Each tier in the tiers array should follow this structure:

PropertyTypeDescription
namestringDisplay name for the tier (e.g., "Bronze", "Silver")
xpRequirednumberPoints required to reach this tier
rewardsstring[]Array of reward descriptions for this tier

Return Value

The function returns a Promise that resolves to an object containing:

{
  collection: KeypairSigner,      // The collection signer for the program
  signature: string,              // Transaction signature
  updateAuthority?: KeypairSigner // Update authority (if provided)
}
PropertyTypeDescription
collectionKeypairSignerThe generated collection keypair that represents your loyalty program
signaturestringThe transaction signature confirming the program creation
updateAuthorityKeypairSignerThe update authority for the loyalty program (if provided)

Error Handling

The function will throw errors in the following cases:

  • Invalid configuration: Missing required parameters or invalid parameter values
  • Image upload failure: If using imageBuffer and the upload fails
  • Metadata generation failure: If metadata cannot be generated from the provided data
  • Transaction failure: If the blockchain transaction fails
  • Insufficient funds: If the fee payer doesn't have enough SOL for the transaction

Important Notes

  • • You must provide either metadataUri OR imageBuffer with imageFilename
  • • The organizationName in metadata is required
  • • At least one tier must be defined in the tiers array
  • • The protocol fee for creating a loyalty program is 0.002 SOL

Related Functions

Next Steps

Advanced Usage