Complete guide to integrating Bitcoin Lightning payments
Get started with Lightning payments in under 10 minutes. Follow these steps to integrate instant Bitcoin payments into your application.
curl -X POST https://api.payaiml.com/v1/keys \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"name": "Lightning Integration", "permissions": ["lightning:read", "lightning:write"]}'
const invoice = await fetch('https://api.payaiml.com/v1/lightning/invoices', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 1000, // satoshis
description: 'Digital content purchase',
expiry: 3600 // 1 hour
})
});
app.post('/webhook/lightning', (req, res) => {
const { invoice_id, status, amount } = req.body;
if (status === 'paid') {
// Payment confirmed - deliver product
console.log(`Payment received: ${amount} sats`);
}
res.status(200).send('OK');
});
Authorization: Bearer your-api-key-here
Security Best Practices
Never expose your API keys in client-side code. Always use server-side requests for Lightning operations.
/v1/lightning/invoices
/v1/lightning/invoices/{id}
/v1/lightning/payments
/v1/lightning/balance
npm install @payaiml/lightning-js
import { LightningClient } from '@payaiml/lightning-js';
const client = new LightningClient('your-api-key');
// Create invoice
const invoice = await client.createInvoice({
amount: 1000,
description: 'Coffee payment'
});
console.log(invoice.payment_request);
{
"event": "payment.received",
"invoice_id": "inv_1234567890",
"amount": 1000,
"status": "paid",
"payment_hash": "abc123...",
"timestamp": "2024-01-15T10:30:00Z"
}
Webhook Security
All webhooks are signed with HMAC-SHA256. Verify the signature to ensure authenticity.
Join thousands of developers already using PayAiML Lightning to power their applications with instant Bitcoin payments.