I just published my first npm package that uses the Lightning Network for micropayments: lightning-bitcoin-query.
The Problem
Traditional API services charge $29-199/month for unlimited requests. But most developers only need a few API calls per day. Why pay for unused quota?
The Solution
Pay-per-query with Lightning Network micropayments:
- 10 sats (~$0.01) per mempool check
- 20 sats (~$0.02) per transaction lookup
- No API keys
- No rate limits
- No subscriptions
How It Works
The package uses the L402 protocol (HTTP 402 Payment Required + Lightning):
const BitcoinQuery = require('lightning-bitcoin-query');
const bitcoin = new BitcoinQuery({
nwcUri: process.env.NWC_URI // From your Lightning wallet
});
// Makes HTTP request → Gets 402 → Pays invoice → Returns data
const mempool = await bitcoin.getMempool();
Behind the scenes:
- Try API request
- Receive 402 Payment Required with Lightning invoice
- Pay invoice automatically via NWC wallet
- Cache payment hash for 5 minutes
- Retry request with payment proof
- Return blockchain data
Why Lightning?
- Instant: Payments confirm in <1 second
- Cheap: Network fees are <1 sat
- Global: Works worldwide, no credit cards
- Private: No personal info required
Use Cases
Perfect for:
- Trading bots needing real-time fee data
- Hobby projects with occasional queries
- Startups testing blockchain integrations
- Anyone who wants pay-as-you-go APIs
Try It
npm install lightning-bitcoin-query
Full docs: https://www.npmjs.com/package/lightning-bitcoin-query
What other APIs would benefit from micropayments? Let me know in the comments!
Top comments (0)