What is LNURL?
LNURL is a set of open protocols that layer on top of Bitcoin’s Lightning Network. They aim to simplify workflows like receiving and paying with Lightning. LNURL can operate in two major directions: LNURL-Pay: Customer pays a static link that auto-fetches the invoice. LNURL-Withdraw: Customer scans a link to claim funds from a service. Instead of manually generating an invoice for each transaction, LNURL allows a user’s wallet to request one on the fly. This makes recurring or unpredictable payments simpler because the user only has to scan a single QR or link once.Common LNURL use cases
- Tipping: A content creator shares an LNURL to receive tips from fans instantly.
- Withdraw: A user can withdraw earnings from a platform by scanning or clicking an LNURL that spawns an invoice behind the scenes.
- Static Donations: Similar to tipping, but used for ongoing donation flows.
Lightning addresses
Lightning addresses provide an even simpler approach: users have an “email-like” identifier (e.g., joe@example.com). When someone wants to send them sats, they type or paste that address into a Lightning wallet that supports LNURL behind the scenes, automatically retrieving an invoice. Receive: The payer’s wallet queries joe@example.com, obtains the invoice, and completes the payment. Send: Similarly, you can pay another user’s Lightning address by letting your system generate the appropriate LNURL flow under the hood.Why Lightning addresses?
Familiar experience: Email or username style format. Great for real-time micropayments or user handles. No manual copying of BOLT11 invoice strings.LNURL + Bitnob integration
With Bitnob, you can:- Issue LNURLs to customers (for receiving or withdrawal flows).
- Issue or manage Lightning addresses for each user.
- Use the same underlying Lightning accounts you already have in Bitnob.
- Listen for LNURL or address-based payments via webhooks.
LNURL setup flows
LNURL-Pay
- User sees a static QR or link (the LNURL).
- Their wallet decodes the LNURL, fetches the invoice, and pays.
- Payment arrives in your Bitnob balance, and Bitnob sends a deposit.success webhook.
LNURL-Withdraw
- Your app shows a user an LNURL code that references your “custody.”
- The user’s wallet scans it, reads the withdrawal limits, and sends Bitnob an invoice it created.
- Payment flows from your side (e.g., a payout) to the user’s LN wallet.
Lightning address setup
- You assign an address to each user (e.g., username@yourdomain.com).
- This domain or subdomain is LNURL-enabled with the help of Bitnob’s API or your own LNURL server.
- When someone pays username@yourdomain.com, Bitnob automatically generates an invoice and forwards the payment to that user’s wallet.
Creating LNURLs and Lightning addresses via API
- Register your domain or subdomain with
POST /api/lnurl/domains, add the DNS records it returns, then callPOST /api/lnurl/domains/{id}/verify. - LNURL-Withdraw: Issue a link with
POST /api/lnurl/withdrawals, settingdomain_id,min_withdraw_sat,max_withdraw_sat, and optionallyttl_seconds. - LNURL-Pay and Lightning addresses: Create name@yourdomain.com with
POST /api/lnurl/addresses, settingdomain_id,identifier,min_sendable_sat,max_sendable_sat, and optionallycomment_max. You can also run your own LNURL server and create invoices through the Lightning API.
Key fields to note
Handling payment notifications
Whenever a LNURL-based or Lightning address-based payment arrives: Webhook: You receive an event like deposit.success from Bitnob, containing the paid invoice details. Idempotency: As always, mark the payment as processed in your DB using a unique reference. Optional Extra Steps: If the LNURL was for a withdrawal, you can automatically finalize the user’s request. If it was a LNURL pay link, you can credit them once confirmed.Security and best practices
- Use unique addresses/LNURLs: Assign a new address or LNURL per user to keep transactions separate.
- Validate domain ownership: If you run your own LNURL domain.
- Set Sane Limits: LNURL withdraw flows can specify maximum amounts to avoid large accidental payouts.
- Track usage: Track each LNURL’s usage so a user can’t keep re-withdrawing if your logic only expects one usage.
- Handle Rate Limits: LNURL-compatible wallets might re-poll your callback. Include some caching or a short TTL.