Verxio Protocol

Mint Voucher

Create and distribute individual vouchers within a collection. You can either provide a pre-uploaded metadata URI or provide an image buffer and filename to auto-upload the image and generate metadata.

1. Using a Pre-uploaded Metadata URI

import { mintVoucher } from '@verxioprotocol/core'
import { generateSigner, publicKey } from '@metaplex-foundation/umi'

const result = await mintVoucher(context, {
  collectionAddress: publicKey('COLLECTION_ADDRESS'),
  voucherName: 'Summer Sale Voucher',
  voucherMetadataUri: 'https://arweave.net/...', // Already uploaded metadata
  voucherData: {
    type: 'percentage_off',
    value: 15, // 15% off
    maxUses: 1,
    expiryDate: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days from now
    conditions: [{ type: 'minimum_purchase', value: 50, operator: 'greater_than' }],
    description: '15% off your next purchase',
    merchantId: 'coffee_brew_merchant_001', // String identifier for the merchant
  },
  recipient: publicKey('RECIPIENT_ADDRESS'),
  updateAuthority: generateSigner(context.umi),
})

2. Uploading an Image and Generating Metadata

import { mintVoucher } from '@verxioprotocol/core'
import { generateSigner, publicKey } from '@metaplex-foundation/umi'
import fs from 'fs'

const imageBuffer = fs.readFileSync('voucher.png')
const result = await mintVoucher(context, {
  collectionAddress: publicKey('COLLECTION_ADDRESS'),
  voucherName: 'Summer Sale Voucher',
  imageBuffer, // Buffer of your image
  imageFilename: 'voucher.png',
  voucherData: {
    type: 'percentage_off',
    value: 15, // 15% off
    maxUses: 1,
    expiryDate: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days from now
    conditions: [{ type: 'minimum_purchase', value: 50, operator: 'greater_than' }],
    description: '15% off your next purchase',
    merchantId: 'coffee_brew_merchant_001', // String identifier for the merchant
  },
  recipient: publicKey('RECIPIENT_ADDRESS'),
  updateAuthority: generateSigner(context.umi),
})
// The protocol will upload the image, generate metadata, and use the resulting URI

Voucher Data Structure

PropertyTypeRequiredDescription
typestringVoucher type: 'percentage_off', 'fixed_verxio_credits', 'free_item', 'buy_one_get_one', 'custom_reward'
valuenumberVoucher value (percentage, amount, etc.)
maxUsesnumberMaximum number of times the voucher can be used
expiryDatenumberExpiration timestamp in milliseconds
conditionsArrayArray of usage conditions
descriptionstringHuman-readable description of the voucher
merchantIdstringString identifier for the merchant

Return Value

{
  asset: KeypairSigner,  // Voucher signer
  signature: string,    // Transaction signature
  voucherAddress: PublicKey // Voucher public key
}