You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript client for the Lightning Charge REST API.
Install
$ npm install lightning-charge-client
Use
// Initialize the clientimportChargeClientfrom'lightning-charge-client'constcharge=newChargeClient('https://localhost:9112','[API-TOKEN]')// new is optionalconstcharge=require('lightning-charge-client')('https://localhost:9112','[API-TOKEN]')// Create invoiceconstinv=awaitcharge.invoice({msatoshi: 50,metadata: {customer_id: 123,product_id: 456}})console.log(`invoice ${inv.id} created with rhash=${inv.rhash}, payreq=${inv.payreq}`)// Create invoice denominated in USDconstinv=awaitcharge.invoice({currency: 'USD',amount: 0.15})// Fetch invoiceconstinvoice=awaitcharge.fetch('m51vlVWuIKGumTLbJ1RPb')// Fetch all invoicesconstinvoices=awaitcharge.fetchAll()// Long poll payment updates for a specific invoicedo{constpaid=awaitcharge.wait(inv.id,/* timeout: */600/* seconds */)if(paid)console.log(`invoice ${paid.id} of ${paid.msatoshi} paid, updated invoice:`,paid)elseif(paid===false)console.log('invoice expired and can no longer be paid')elseif(paid===null)console.log('timeout reached without payment, invoice is still payable')}while(paid===null)// Stream all incoming paymentsconststream=charge.stream()stream.on('payment',inv=>console.log(`invoice ${inv.id} of ${inv.msatoshi} paid`))