/lnpay

NPM Package for LNPay.co API.

Primary LanguageTypeScript

LNPay NodeJS API

npm version NPM Known Vulnerabilities License: MIT


The goal of the LNPay API is to create a toolkit interface for interaction between nodes and external services.


Donate

Help me to stack sats! 😊

Donate via Lightning Network!


Features


Installation

Using npm:

$ npm install lnpay

Using yarn:

$ yarn add lnpay

Usage

Initial Config

Initial LNPay configuration.

import LNPay from 'lnpay';

const lnpay = LNPay({
  secretKey: 'pak_O0iUMxk8kK_qUzkT4YKFvp1ZsUtp',
  walletAccessKey: 'waka_kqvaiFFl4Tjq4rgAXlwsu6',
});

Create Wallet

Create a new wallet and corresponding access keys.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {string} params.user_label - An internal identifier for this
const wallet = await lnpay.createWallet({
  user_label: 'My Wallet',
});
console.log(wallet);

Get Balance

Returns info about the wallet, including balance.

Official Documentation / Code Example

const balance = await lnpay.getBalance();
console.log(balance);

Get Transactions

Get a list of wallet transactions that have been SETTLED. This includes only transactions that have an impact on wallet balance. These DO NOT include unsettled/unpaid invoices.

Official Documentation / Code Example

Parameters:

  • {Object} [params] - Params object.
  • {number} [params.page] - Page number.
const transactions = await lnpay.getTransactions({
  page: 1,
});
console.log(transactions);

Generate Invoice

Generate a new Invoice payment.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {number} params.num_satoshis - The number of satoshis of the invoice.
  • {Object} [params.passThru] - JSON object. you can reference these parameters later via webhooks, etc. Good for ticket # or a certain ID.
  • {string} [params.description_hash] - base64 encoded hash of payment. If this is provided, memo will be ignored.
  • {Object} [params.memo] - Add a memo text.
  • {Object} [params.expiry] - Expires in seconds, defaults to 86400 (1 day)
const invoice = await lnpay.generateInvoice({
  num_satoshis: 100,
  passThru: {
    order_id: '100',
  },
  description_hash: 'MTIzNDY1Nzg5N...',
  memo: 'Invoice memo.',
  expiry: 86400, // 1 day
});
console.log(invoice);

Pay Invoice

Generate an LN payment invoice from the specified wallet.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {string} params.payment_request - Payment request string.
  • {Object} [params.passThru] - JSON object of custom data to pass thru.
const payInvoice = await lnpay.payInvoice({
  payment_request: 'lnbc50n1p0qjf84p...',
  passThru: {
    order_id: '100',
  },
});
console.log(payInvoice);

Keysend

Initiate a keysend payment from your wallet to a destination pubkey.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {number} params.dest_pubkey - Pubkey of destination node.
  • {Object} params.num_satoshis - The number of satoshis of the invoice.
  • {string} [params.passThru] - Data to pass along with this invoice for webhooks (e.g. ticketId, etc)
  • {Object} [params.custom_records] - key:value pairs to be sent in the onion. key must be an integer greater than 65536. value must be a string, encoded binary data is not supported. Too many values here will break things.
const keysend = await lnpay.keysend({
  passThru: {
    order_id: '100',
  },
  dest_pubkey: '033868c219bdb51a3...',
  num_satoshis: 1,
});
console.log(keysend);

Transfer Between Wallets

This section describes how to transfer sats between wallets within LNPay.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {string} params.dest_wallet_id - Destination wallet access key (WAK) or wallet_id
  • {number} params.num_satoshis - Sats for this transfer
  • {string} params.memo - Memo note for this transfer
  • {string} params.lnPayParams - JSON array of custom data to pass thru.
const transfer = await lnpay.transfer({
  dest_wallet_id: 'w_n743yizWqe43Oz',
  num_satoshis: 1,
  memo: 'Transfer Memo',
  lnPayParams: {
    order_id: '100',
  },
});
console.log(transfer);

LN Url Withdraw

Generate an LNURL-withdraw link.

Official Documentation / Code Example

Parameters:

  • {Object} [params] - Params object.
  • {boolean} [params.public] - (default: false) if set to true, the LNURL will be a one-time allowable withdraw for the amount set with no sensitive data in the LNURL. Good for public use.
  • {string} [params.passThru] - Base64 encoded json of data to use in webhooks, etc
  • {string} [params.memo] - Memo note for the invoice.
  • {number} [params.num_satoshis] - Max number of satoshis this LNURL is good for. If blank max wallet balance is used.
const lnUrlWithdraw = await lnpay.lnUrlWithdraw({
  public: false,
  memo: 'LNURL Withdraw memo',
  num_satoshis: 3,
});
console.log(lnUrlWithdraw);

Get Invoice Status

Retrieve a LN transaction (invoice). This is usually used to see if a transaction has been settled or not, and for how much.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {string} params.id - Transaction id. e.g. lntx_82yveCX2Wn0EkkdyzvyBv
const getInvoice = await lnpay.getInvoice({
  id: 'lntx_82yveCX2Wn0EkkdyzvyBv',
});
console.log(getInvoice);

Create Paywall

Retrieve a LN transaction (invoice). This is usually used to see if a transaction has been settled or not, and for how much.

Official Documentation / Code Example

Parameters:

  • {Object} params - Params object.
  • {string} params.destination_url
  • {string} params.memo
  • {string} params.short_url
  • {number} params.num_satoshis
const paywall = await lnpay.createPaywall({
  destination_url: 'https://bigsun.xyz',
  memo: 'This is my memo',
  short_url: 'bigsun',
  num_satoshis: 100,
});
console.log(paywall);

References


Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


License

MIT