<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rod Millz</title>
    <description>The latest articles on DEV Community by Rod Millz (@rodmillz).</description>
    <link>https://dev.to/rodmillz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3658019%2F45ad4612-c9d6-4da9-a75b-6582eb1b1b96.png</url>
      <title>DEV Community: Rod Millz</title>
      <link>https://dev.to/rodmillz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rodmillz"/>
    <language>en</language>
    <item>
      <title>Building an npm Package with Lightning Network Micropayments (L402)</title>
      <dc:creator>Rod Millz</dc:creator>
      <pubDate>Fri, 12 Dec 2025 02:17:46 +0000</pubDate>
      <link>https://dev.to/rodmillz/building-an-npm-package-with-lightning-network-micropayments-l402-48fi</link>
      <guid>https://dev.to/rodmillz/building-an-npm-package-with-lightning-network-micropayments-l402-48fi</guid>
      <description>&lt;p&gt;I just published my first npm package that uses the Lightning Network for micropayments: &lt;code&gt;lightning-bitcoin-query&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;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?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;Pay-per-query with Lightning Network micropayments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;10 sats (~$0.01) per mempool check&lt;/li&gt;
&lt;li&gt;20 sats (~$0.02) per transaction lookup&lt;/li&gt;
&lt;li&gt;No API keys&lt;/li&gt;
&lt;li&gt;No rate limits&lt;/li&gt;
&lt;li&gt;No subscriptions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;The package uses the L402 protocol (HTTP 402 Payment Required + Lightning):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BitcoinQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lightning-bitcoin-query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bitcoin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BitcoinQuery&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;nwcUri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NWC_URI&lt;/span&gt; &lt;span class="c1"&gt;// From your Lightning wallet&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Makes HTTP request → Gets 402 → Pays invoice → Returns data&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mempool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;bitcoin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getMempool&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Try API request&lt;/li&gt;
&lt;li&gt;Receive 402 Payment Required with Lightning invoice&lt;/li&gt;
&lt;li&gt;Pay invoice automatically via NWC wallet&lt;/li&gt;
&lt;li&gt;Cache payment hash for 5 minutes&lt;/li&gt;
&lt;li&gt;Retry request with payment proof&lt;/li&gt;
&lt;li&gt;Return blockchain data&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Lightning?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Instant:&lt;/strong&gt; Payments confirm in &amp;lt;1 second&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cheap:&lt;/strong&gt; Network fees are &amp;lt;1 sat&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global:&lt;/strong&gt; Works worldwide, no credit cards&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Private:&lt;/strong&gt; No personal info required&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Use Cases
&lt;/h2&gt;

&lt;p&gt;Perfect for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trading bots needing real-time fee data&lt;/li&gt;
&lt;li&gt;Hobby projects with occasional queries&lt;/li&gt;
&lt;li&gt;Startups testing blockchain integrations&lt;/li&gt;
&lt;li&gt;Anyone who wants pay-as-you-go APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;lightning-bitcoin-query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Full docs: &lt;a href="https://www.npmjs.com/package/lightning-bitcoin-query" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/lightning-bitcoin-query&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What other APIs would benefit from micropayments? Let me know in the comments!&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>node</category>
      <category>micropayments</category>
    </item>
  </channel>
</rss>
