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
Property | Type | Required | Description |
---|---|---|---|
type | string | ✅ | Voucher type: 'percentage_off', 'fixed_verxio_credits', 'free_item', 'buy_one_get_one', 'custom_reward' |
value | number | ✅ | Voucher value (percentage, amount, etc.) |
maxUses | number | ✅ | Maximum number of times the voucher can be used |
expiryDate | number | ✅ | Expiration timestamp in milliseconds |
conditions | Array | ❌ | Array of usage conditions |
description | string | ✅ | Human-readable description of the voucher |
merchantId | string | ✅ | String identifier for the merchant |
Return Value
{ asset: KeypairSigner, // Voucher signer signature: string, // Transaction signature voucherAddress: PublicKey // Voucher public key }