Arcadia SDK - Payment Example

Initializing SDK...

Pay to Play

In-Game Purchase

Code Example

// Pay to play - all payment details included
try {
  const result = await arcadia.payment.payToPlay(0.5, 'SOL');
  
  // No need to query blockchain - all details provided
  console.log('Payment successful!');
  console.log('Amount:', result.amount, result.token);
  console.log('Transaction:', result.txSignature);
  console.log('Timestamp:', result.timestamp);
  console.log('Purchase ID:', result.purchaseId);
  console.log('Platform fee:', result.platformFee);
  console.log('Developer receives:', result.developerAmount);
  
  // Store in your database
  await savePurchase(result);
  startGame();
} catch (error) {
  console.error('Payment failed:', error.message);
}

// Purchase item - complete payment details
try {
  const result = await arcadia.payment.purchaseItem('sword-001', 1.0, 'SOL');
  
  // Verify payment details
  if (result.success && result.amount === 1.0) {
    addItemToInventory('sword-001');
    await logPurchase({
      itemId: 'sword-001',
      ...result
    });
  }
} catch (error) {
  console.error('Purchase failed:', error.message);
}