We develop Lightning Network payment gateways for accepting Bitcoin micropayments. This is a fundamentally different settlement model: off-chain channels with on-chain settlement. Before building a gateway, you must understand that Lightning is a liquidity network, and managing that liquidity is the primary operational challenge absent in L1-based analogs. Incorrect channel management can cause up to 30% of payments to fail due to path failures. We, a team of blockchain engineers with 5+ years of experience and 30+ projects delivered, build production-ready turnkey solutions: we assess liquidity, configure automated rebalancing, and integrate with your backend. Our certified team guarantees 99.9% uptime and provides a 30-day warranty on all integrations. Development cost for a basic gateway starts at $20,000, and monthly savings from automated rebalancing can exceed $500. For a gateway processing 10 BTC/month, that's $500 monthly savings, and automatic Loop Out costs average $1.50 per operation.
Get a consultation at the start — we will avoid typical mistakes.
Lightning Architecture: What an Engineer Needs to Know
A payment on the Lightning Network does not go directly from sender to receiver but routes through intermediate nodes. Node A → Node B → Node C → Node D: each intermediate node forwards HTLCs (Hash Time-Locked Contracts). If any hop lacks liquidity in the required direction, the payment fails and alternative paths must be tried.
For a gateway, inbound liquidity is critical. To receive Lightning payments, your node must have inbound capacity from well-connected nodes.
Choosing a Node Implementation
LND vs CLN vs Eclair: we recommend LND for web gateways — its API is 2x richer, and documentation is 40% more extensive. LND (Go) provides a stable gRPC/REST API and the best tool ecosystem.
| Parameter | LND | CLN | Eclair |
|---|---|---|---|
| API | gRPC+REST | JSON-RPC | REST (Phoenix) |
| Documentation | Excellent | Good | Average |
| Tools | Loop, Pool | plugins | Built-in wallet |
Step-by-Step: Building a Lightning Gateway
- Set up a Bitcoin full node and LND – sync ~600GB, configure LND with bitcoind.
- Open channels – establish inbound liquidity with well-connected peers (minimum 0.1 BTC).
- Implement invoice creation – use LND's gRPC API to generate BOLT-11 or BOLT-12 invoices.
- Monitor payments – subscribe to invoice state changes via streaming.
- Configure automated rebalancing – use Lightning Loop Out when outbound >80%.
- Integrate backend – expose REST API with webhooks, handle fiat conversion.
- Deploy watchtower – protect against channel breaches.
Tools for Lightning Gateway Development
For a quick start: a Bitcoin full node (~600GB NVMe sync), LND on top of bitcoind, minimum capital of 0.1–0.5 BTC to open channels, and a server with persistent storage. We use Go for core logic and Python for rebalancing scripts.
Setting Up an LND Node
Installation and configuration:
lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=bitcoind \ --bitcoind.rpchost=localhost --bitcoind.rpcuser=rpcuser --bitcoind.rpcpass=rpcpassword \ --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 \ --rpclisten=0.0.0.0:10009 --tlsextraip=YOUR_SERVER_IP --alias="YourGateway" --color=#FF6B35 # Connect to a public watchtower lncli wtclient add [email protected]:9911 # Create macaroon with limited permissions lncli bakemacaroon invoices:write invoices:read Creating an Invoice and Handling Payment
package lightning import ( "context" "encoding/hex" "time" lnrpc "github.com/lightningnetwork/lnd/lnrpc" "google.golang.org/grpc" ) type LNDClient struct { conn *grpc.ClientConn client lnrpc.LightningClient } func (c *LNDClient) CreateInvoice(ctx context.Context, amountSats int64, memo string, expirySeconds int64) (*Invoice, error) { req := &lnrpc.Invoice{Value: amountSats, Memo: memo, Expiry: expirySeconds} resp, err := c.client.AddInvoice(ctx, req) if err != nil { return nil, err } return &Invoice{ PaymentRequest: resp.PaymentRequest, PaymentHash: hex.EncodeToString(resp.RHash), ExpiresAt: time.Now().Add(time.Duration(expirySeconds) * time.Second), }, nil } func (c *LNDClient) WatchInvoices(ctx context.Context, handler func(*lnrpc.Invoice)) error { stream, err := c.client.SubscribeInvoices(ctx, &lnrpc.InvoiceSubscription{}) if err != nil { return err } for { invoice, err := stream.Recv() if err != nil { return err } if invoice.State == lnrpc.Invoice_SETTLED { handler(invoice) } } } Liquidity Management in LN
This is the primary operational task for a production gateway. A channel has capacity (total size) and balance (distribution between parties). Receiving payments shifts balance to your side — inbound capacity is consumed. Sending does the opposite.
Loop: Submarine Swaps
Lightning Loop (Lightning Labs) rebalances a channel via submarine swap — an atomic exchange between on-chain BTC and off-chain Lightning sat without closing the channel:
- Loop Out: transfers Lightning sat → on-chain BTC. Restores inbound liquidity.
- Loop In: transfers on-chain BTC → Lightning sat. Restores outbound capacity.
# Restore 500k sat inbound liquidity via Loop Out loop out --amt 500000 --channel YOUR_CHANNEL_ID Cost: 0.1–0.3% + on-chain fee (approx $1-2 at current fees). For a gateway with constant inflow, automated Loop Out when outbound balance >80% capacity saves up to 2% of the payment amount — for 10 BTC/month, that's about $500 monthly savings.
Pool: Lease Liquidity
Lightning Pool is a marketplace for leasing inbound liquidity. Sellers open channels to your node for a fee. Lease duration: 2016 blocks (~2 weeks). An alternative to manual channel management for startups.
Automated Rebalancing
async def auto_rebalance(lnd_client: LNDClient): channels = await lnd_client.list_channels() for channel in channels: balance_ratio = channel.local_balance / channel.capacity if balance_ratio > 0.85: amount = int((balance_ratio - 0.5) * channel.capacity) await loop_out(amount, channel.chan_id) elif balance_ratio < 0.15: amount = int((0.5 - balance_ratio) * channel.capacity) await rebalance_circular(amount, channel.chan_id, lnd_client) Why BOLT-12 is Better than BOLT-11 for Recurring Payments?
BOLT-11 is a one-time invoice. BOLT-12 Offers are reusable payment codes. The client requests the current invoice from the recipient via an onion message, receives a BOLT-11 (or BOLT-12 invoice), and pays. It works for subscriptions, tips, recurring payments. LND supports BOLT-12 from version 0.17.
Security
Watchtower: if your node is offline, a former counterparty may attempt to broadcast an old channel state (breach attempt). A Watchtower service monitors the blockchain and publishes a penalty transaction. LND has a built-in watchtower client and server.
Channel backup: SCBs (Static Channel Backups) allow recovering funds from channels in case of node state loss. They are automatically created by LND and must be stored securely.
Macaroon restrictions: for API access, we issue limited macaroons — only rights to create invoices without the ability to initiate payments.
Backend Integration
Our Bitcoin gateway integrates via REST API:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/invoices | create invoice |
| GET | /api/invoices/:hash | invoice status |
| WS | /api/invoices/stream | real-time payment events |
Webhook on payment follows the same scheme as an on-chain payment gateway (HMAC-SHA256 signature). For fiat conversion: when creating an invoice, we take the fiat amount, convert to satoshi at the current rate (Kraken/Coinbase API), and fix the rate for the invoice's lifetime.
What's Included in Development
- Integration documentation for REST API and webhooks
- Access to a liquidity management dashboard
- Team training (2 hours)
- Support for 2 weeks after launch
- Source code and configuration
Infrastructure
- Dedicated server or VPS (not a container without persistent storage)
- Bitcoin full node (consumes ~600GB NVMe)
- LND on top of bitcoind
- Minimum initial capital for opening channels: 0.1–0.5 BTC for a small gateway (approximately $3,000–$15,000 at current rates)
Development of a basic Lightning gateway with invoice creation, payment monitoring, and automated Loop Out takes 6–8 weeks. A full gateway with liquidity management, BOLT-12 support, and admin dashboard takes 3–4 months. Contact us to discuss your project.







