credits

manage credit balance and purchase credits with usdc

check balance

// Check your credit balance
const balance = await client.getCreditBalance();

console.log(`Available: ${balance.available} credits`);
console.log(`Reserved: ${balance.reserved} credits`);
console.log(`Total used: ${balance.totalUsed} credits`);

// Reserved credits are held for active deployments
// Available = total - reserved - used

view credit packages

// Get available credit packages
const packages = await client.getCreditPackages();

// Returns:
// [
//   {
//     id: 'pkg_starter',
//     name: 'Starter',
//     credits: 100,
//     priceUsd: 10,
//     bonusPercent: 0,
//   },
//   {
//     id: 'pkg_pro',
//     name: 'Pro',
//     credits: 550,
//     priceUsd: 50,
//     bonusPercent: 10,
//   },
//   ...
// ]

purchase credits

// Step 1: Initiate deposit
const deposit = await client.initiateDeposit('pkg_pro', walletAddress);

console.log(`Send ${deposit.amountUsdc} USDC to ${deposit.treasuryWallet}`);
console.log(`Deposit ID: ${deposit.depositId}`);
console.log(`Expires at: ${deposit.expiresAt}`);

// Step 2: Send USDC transaction via your wallet
const txSignature = await sendUsdcTransaction(
  deposit.treasuryWallet,
  deposit.amountUsdc,
  deposit.usdcMint
);

// Step 3: Confirm the deposit
const transaction = await client.confirmDeposit(
  deposit.depositId,
  txSignature
);

console.log(`Received ${transaction.amount} credits!`);

important notes:

  • • deposits are made using usdc on solana
  • • deposit sessions expire after 30 minutes
  • • credits are added after blockchain confirmation

transaction history

// View transaction history
const { data, pagination } = await client.getCreditTransactions({
  type: 'deposit',  // 'deposit', 'usage', 'refund'
  page: 1,
  limit: 20,
});

// Transaction structure:
// {
//   id: 'tx_123',
//   type: 'deposit',
//   amount: 550,
//   description: 'Pro package purchase',
//   createdAt: '2024-01-15T10:30:00Z',
//   txSignature: 'abc123...',  // Solana tx signature
// }

credit types

interface CreditBalance {
  available: number;
  reserved: number;
  totalUsed: number;
}

interface CreditPackage {
  id: string;
  name: string;
  credits: number;
  priceUsd: number;
  bonusPercent: number;
}

interface CreditTransaction {
  id: string;
  type: 'deposit' | 'usage' | 'refund' | 'bonus';
  amount: number;
  description: string;
  createdAt: string;
  txSignature?: string;
  deploymentId?: string;
}