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');
}import requests
import os
response = requests.post(
'https://api.heaven402.com/v1/payments/verify',
headers={
'Content-Type': 'application/json',
'Authorization': f'Bearer {os.getenv("API_KEY")}'
},
json={
'payment_proof': 'BASE64_ENCODED_PAYMENT_PROOF',
'amount': 1000000,
'recipient': 'YOUR_WALLET_ADDRESS'
}
)
data = response.json()
if data['verified']:
print(f'Payment verified! Transaction: {data["transaction_id"]}')
else:
print('Payment invalid')Language-Specific Guides
JavaScript/TypeScript - Node.js and browser examples
Python - Sync and async examples
Rust - Reqwest and tokio examples
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
Keep API keys secret - Never expose them in frontend code
Validate amounts - Always check the payment amount matches what you expect
Handle errors gracefully - Network issues happen, handle them properly
Log everything - Keep logs for debugging and reconciliation
Start small - Test with small amounts before going live
Use WebSockets - Get real-time notifications when payments arrive
Next Steps
Pick your language and see detailed examples:
Last updated
