invoice-any
v1.2.0
Published
Generate Lightning Network invoices from Lightning addresses or LNURL
Maintainers
Readme
⚡ invoice-any
Generate Lightning Network invoices from Lightning addresses or LNURL with ease!
❓ What is it?
invoice-any is a lightweight Node.js package that allows you to generate Lightning Network invoices directly from a Lightning Address (e.g., [email protected]) or an LNURL. It simplifies the process of interacting with the Lightning Network for payments.
📦 Installation
You can install the package using npm:
npm install invoice-any🚀 How to use it?
💻 As a Library
Import the package into your project and use the getInvoice function.
const { getInvoice, AmountOutOfRangeError } = require('invoice-any');
const address = '[email protected]'; // Or an LNURL
const amountSats = 1000; // Amount in satoshis (decimals are rounded)
try {
const invoice = await getInvoice(address, amountSats);
console.log('⚡ Generated Invoice:', invoice);
} catch (error) {
if (error instanceof AmountOutOfRangeError) {
console.error('Amount out of range:', error.message);
} else {
console.error('❌ Error:', error.message);
}
}⌨️ CLI Usage
You can also use it directly from the command line to generate invoices instantly.
Syntax:
get-invoice <lightning-address-or-lnurl> <amount-in-sats>Example:
# Using npx (no installation needed)
npx invoice-any [email protected] 500
# Or if installed globally
get-invoice [email protected] 500✅ Supported Wallets
This package supports any wallet or service that implements the Lightning Address or LNURL protocol.
Some popular examples include:
- ⚡ Wallet of Satoshi
- 🟠 Blink (Bitcoin Beach)
- 🐝 Alby
- 🦅 Phoenix (via LNURL)
- 🟣 ZBD
- And many others!
🛠 Dependencies
This package relies on the following dependencies:
- bech32: Used for decoding LNURL strings. 🔗
📊 Usage monitoring (Umami)
The package can send anonymous usage events to Umami so you can count how often getInvoice is called from the npm package or CLI.
Each event is named invoice-any.usage and includes:
| Field | Description |
|-------|-------------|
| package | invoice-any |
| version | Installed package version |
| source | library or cli |
| path | lnaddress or lnurl |
| success | Whether the invoice was generated |
| duration_ms | Time taken |
| error_code | Error code on failure (no addresses or amounts) |
Setup — set your Umami website ID:
export INVOICE_ANY_UMAMI_WEBSITE_ID="your-website-id"
# optional, defaults to Umami Cloud:
export INVOICE_ANY_UMAMI_HOST="https://cloud.umami.is"Or configure in code:
const { configureTelemetry, getInvoice } = require('invoice-any');
configureTelemetry({
websiteId: 'your-website-id',
hostUrl: 'https://cloud.umami.is', // or your self-hosted instance
});
const invoice = await getInvoice('[email protected]', 1000);Opt out (per call or globally):
await getInvoice('[email protected]', 1000, { telemetry: false });INVOICE_ANY_TELEMETRY=0 npm run your-scriptIn Umami, open Events and filter by invoice-any.usage to see total usage and breakdown by source, path, and success.
ℹ️ Additional Information
- Node.js: 18 or newer (uses native
fetch) - License: MIT
Happy Hacking! 🚀
