Quick Start Examples

Code examples for accepting x402 payments with Heaven402 in various programming languages.

Quick Start

Verify an x402 Payment

The simplest way to accept a payment:

const response = await fetch('https://api.heaven402.com/v1/payments/verify', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.API_KEY}`
  },
  body: JSON.stringify({
    payment_proof: 'BASE64_ENCODED_PAYMENT_PROOF',
    amount: 1000000,
    recipient: 'YOUR_WALLET_ADDRESS'
  })
});

const data = await response.json();
if (data.verified) {
  console.log('Payment verified! Transaction:', data.transaction_id);
} else {
  console.log('Payment invalid');
}

Language-Specific Guides

Integration Patterns

Protect an API Endpoint

Add x402 payments to any API endpoint:

Real-Time Payment Notifications

Get notified instantly when payments arrive:

Build a Paywall

Simple paywall for content:

Best Practices

  1. Keep API keys secret - Never expose them in frontend code

  2. Validate amounts - Always check the payment amount matches what you expect

  3. Handle errors gracefully - Network issues happen, handle them properly

  4. Log everything - Keep logs for debugging and reconciliation

  5. Start small - Test with small amounts before going live

  6. Use WebSockets - Get real-time notifications when payments arrive

Next Steps

Pick your language and see detailed examples:

Last updated