Lightning Network Documentation

Complete guide to integrating Bitcoin Lightning payments

Lightning NetworkAPI v1REST & WebSocket

Quick Start Guide

Get started with Lightning payments in under 10 minutes. Follow these steps to integrate instant Bitcoin payments into your application.

1
Create Account
Sign up for PayAiML and verify your business details.
2
Generate API Keys
Create your Lightning API keys in the dashboard.
curl -X POST https://api.payaiml.com/v1/keys \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"name": "Lightning Integration", "permissions": ["lightning:read", "lightning:write"]}'
3
Create Invoice
Generate a Lightning invoice for payment.
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
  })
});
4
Handle Payment
Listen for payment confirmations via webhooks.
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');
});

Authentication

API Key Authentication
All API requests require authentication using your API key in the Authorization header.
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.

API Reference

POST/v1/lightning/invoices
Create a new Lightning invoice
Parameters:
amountdescriptionexpiry?
GET/v1/lightning/invoices/{id}
Get invoice status and details
Parameters:
id
POST/v1/lightning/payments
Send Lightning payment
Parameters:
invoiceamount?
GET/v1/lightning/balance
Get Lightning wallet balance
Parameters:None

SDKs & Libraries

JavaScript SDK
Official JavaScript library for Lightning integration

Installation

npm install @payaiml/lightning-js

Example Usage

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);

Webhooks

Payment Notifications
Receive real-time notifications when Lightning payments are received or updated.

Webhook Payload Example

{
  "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.

Integration Examples

E-commerce Integration
Accept Lightning payments in your online store
Content Monetization
Paywall and micropayments for digital content
API Monetization
Charge per API call with Lightning
Gaming Integration
In-game purchases and rewards

Ready to start building?

Join thousands of developers already using PayAiML Lightning to power their applications with instant Bitcoin payments.