makeInvoice

Request that the user creates an invoice to be used by the web app. This will return a BOLT-11 invoice. Invoices can be requested in a few forms:

  • By specifying an explicit amount, the user's provider should enforce that the user generate an invoice with a specific amount

  • By specifying a minimumAmount and / or maximumAmount, the user's provider should enforce that the user generate an invoice with an amount field constrained by that amount

  • When an explicit amount is not set, the us

Amounts are denominated in satoshis. For large amounts, it's recommended you use a big number library such as bn.js or big.js as Javascript only supports 32 bit integers.

Method

async function makeInvoice(args: RequestInvoiceArgs): RequestInvoiceResponse

Params

  • eventrequired object

    • amountoptional string|number the satoshis to send

    • defaultAmountoptional string|number

    • minimumAmountoptional string|number

    • maximumAmountoptional string|number

    • defaultMemooptional string

interface RequestInvoiceArgs {
  amount?: string | number; // unit is sats
  defaultAmount?: string | number; // unit is sats
  minimumAmount?: string | number; // unit is sats
  maximumAmount?: string | number; // unit is sats
  defaultMemo?: string;
}

Response

interface RequestInvoiceResponse {
  paymentRequest: string;
  paymentHash: string;
  rHash: string;
}

Example

const provider = (window.$onekey && window.$onekey.webln) || window.webln;

await provider.enable();
const invoice = await provider.makeInvoice({
  amount: 1000,
});

Demo

Last updated