Skip to content

timkaebisch/lnbits-wallet-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LNbits Wallet Manager

Command-line tool for managing demo wallets in LNbits for vending machine applications.

Node.js LNbits

Background

In 2023, we built a Bitcoin Lightning vending machine prototype demonstrated at various events. To enable everyone to test Lightning payments without technical barriers, we needed easily accessible demo wallets. LNbits browser-based wallets are perfect for this use case - no installation, no sign-up required.

Initially, we manually created demo wallets (which was time-consuming). This tool automates the entire process: wallet creation, funding, QR code generation, and cleanup.

Watch the vending machine demo

Features

  • Automated Wallet Creation: Bulk create and fund demo wallets
  • QR Code Generation: Generate flyers with wallet QR codes
  • PDF Compilation: Combine all flyers into printable PDF
  • Balance Management: Monitor wallet balances across all demos
  • Smart Cleanup: Defund and delete wallets below threshold
  • Rate Limiting: Respects LNbits API limits automatically
  • Customizable Flyers: Position QR codes on your custom flyer design

Quick Start

Prerequisites

  • Node.js 16+
  • LNbits instance with User Manager extension enabled
  • Admin wallet with sufficient funds for demo wallets

Installation

  1. Clone and install dependencies:

    git clone https://github.com/timkaebisch/lnbits-wallet-manager.git
    cd lnbits-wallet-manager
    npm install
  2. Configure environment:

    cp .env.example .env

Environment Configuration

Edit .env with your settings:

# LNbits Connection
BASE_URL=your_base_url                       # Your LNbits instance URL
ADMIN_KEY=your_admin_wallet_key              # Admin wallet invoice key
USER_ADMIN_ID=your_user_manager_id           # User Manager admin ID
RATE_LIMIT=200                               # API requests per minute

# Flyer Configuration  
BASE_IMAGE_FILE=flyer.png                    # Base flyer image (in base-images/)
OUTPUT_FOLDER=output                         # Output directory
SETUP_URL="https://demo.lnbits.com/wallet?usr=xxx&wal=xxx"  # Test wallet URL

# QR Code Positioning (for demo-flyer-english/german.png)
QR_CODE_X=130                                # X coordinate for QR placement
QR_CODE_Y=1120                               # Y coordinate for QR placement  
QR_CODE_SIZE=495                             # QR code size (width & height)

# PDF Layout
ENABLE_CUTTING_LINE=true                     # Draw cutting guides
LINE_WIDTH=0.1                               # Cutting line thickness

Tip: Use the demo flyers in ./base-images/ or create your own A5 flyer (105×148mm)

Usage

All scripts are accessed through the main manager:

node manager.js -command

Available Commands

Command Description
-setup Setup QR code positioning on flyer
-create Create and fund demo wallets
-balances Show balances of all demo wallets
-clear Delete wallets with balance below threshold
-limit Test API rate limits (use with caution)
-help Show help information

Scripts Reference

1. Setup QR Code Position (-setup)

Position QR codes correctly on your flyer template.

Usage:

node manager.js -setup

Example Output:

Setup QR-Code on flyer
 └ Base image: base-images/flyer.png
 └ Coordinates: X: 130, Y: 1120
 └ Size: 495 x 495

Created setup flyer ✅ Check out the file here: output/setup-flyer.png

2. Create Demo Wallets (-create)

Bulk create, fund, and generate flyers for demo wallets.

Usage:

node manager.js -create

Example Output:

Amount Wallets: 5
Amount initial funding (in sats): 1000

Creating 5 demo wallets with 1000 sats funding each...
Total API requests needed: 15 (3 per wallet)

Processing wallet 1/5...
  ├─ Created wallet 1/5
  ├─ Funded with 1000 sats
  └─ Generated flyer 1.png

Processing wallet 2/5...
  ├─ Created wallet 2/5  
  ├─ Funded with 1000 sats
  └─ Generated flyer 2.png

[... continues for all wallets ...]

All 5 wallets created successfully ✅
Creating PDF document...
PDF saved as: output/2025-12-13_10-30-45/wallets.pdf
Process completed ✅

3. List Wallet Balances (-balances)

Monitor balances across all demo wallets.

Usage:

node manager.js -balances

Example Output:

Listing the balances of all wallets...

Found 5 total wallets

Wallet (abc123def456): 850 sats
Wallet (def456ghi789): 1000 sats  
Wallet (ghi789jkl012): 200 sats
Wallet (jkl012mno345): 0 sats
Wallet (mno345pqr678): 750 sats

4. Delete Low Balance Wallets (-clear)

Clean up wallets below a specified balance threshold.

Usage:

node manager.js -clear

Example Output:

Delete all wallets with less than ... sats: 500

Finding wallets with balance below 500 sats...
Found 5 total wallets
Checking balances of 5 wallets...

Wallet 1/5 (abc123def456): 850 sats
Wallet 2/5 (def456ghi789): 1000 sats
Wallet 3/5 (ghi789jkl012): 200 sats  
Wallet 4/5 (jkl012mno345): 0 sats
Wallet 5/5 (mno345pqr678): 750 sats

Found 2 wallets to delete (balance ≤ 500 sats)

Processing 2 wallet deletions...
Total requests needed: 8 (4 per wallet)

Processing wallet 1/2 (ghi789jkl012)...
  ├─ Transferred 200 sats to admin wallet
  ├─ Deleted wallet ghi789jkl012
  └─ Deleted user usr789

Processing wallet 2/2 (jkl012mno345)...
  ├─ Transferred 0 sats to admin wallet  
  ├─ Deleted wallet jkl012mno345
  └─ Deleted user usr012

Done ✅

5. Test Rate Limits (-limit)

CAUTION: Use carefully - may temporarily block your IP on demo servers.

Usage:

node manager.js -limit

Example Output:

CAUTION: If you are using the demo server of LNbits your IP might get blocked for some minutes/hours
This script continuously sends requests to the endpoint to check the rate limit
Do you want to proceed (y/n): y

Testing limit... Total requests: 198
Testing limit... Total requests: 199  
Testing limit... Total requests: 200

Received the following error message: Rate limit exceeded
Rate limit: 200

File Structure

lnbits-wallet-manager/
├── manager.js                  # Main command interface
├── package.json                # Dependencies
├── .env.example                # Environment template
├── README.md                   # This documentation
├── base-images/                # Flyer templates
│   ├── flyer.png               # Base flyer template
│   ├── demo-flyer-english.png
│   └── demo-flyer-german.png
├── scripts/                    # Core functionality
│   ├── createDemoWallets.js    # Wallet creation & funding
│   ├── listBalances.js         # Balance monitoring  
│   ├── deleteAllWallets.js     # Wallet cleanup
│   ├── setupFlyerQrCode.js     # QR positioning
│   └── testRateLimit.js        # API testing
└── output/            # Generated files (timestamped folders)
    └── 2025-12-13_10-30-45/
        ├── wallets.pdf         # Combined PDF
        └── PNGs/               # Individual flyers
            ├── flyer1.png
            ├── flyer2.png
            └── ...

Custom Flyers

Create A5 flyers (105×148mm) and place them in base-images/. Use -setup to position QR codes correctly, then update your .env coordinates.

About

Management of demo wallets using the LNbits User Manager.

Topics

Resources

License

Stars

Watchers

Forks

Contributors