Skip to Content
dApp 接入
本页目录

makeInvoice

请求用户创建一个供 Web 应用使用的发票。这将返回一个 BOLT-11  发票。发票可以通过以下几种方式请求:

  • 指定 amount 时,provider 应要求用户生成指定金额的发票。
  • 指定 minimumAmount 或 maximumAmount 时,provider 应将发票金额限制在相应范围内。
  • 未指定 amount 时,用户可以在设定范围内选择金额。

金额单位为 satoshi。JavaScript number 仅能精确表示不超过 Number.MAX_SAFE_INTEGER(2^53 - 1)的整数。超过此范围时,应使用十进制字符串;该 API 接受字符串和数值两种类型。

方法

declare function makeInvoice(args: RequestInvoiceArgs): Promise<RequestInvoiceResponse>;

参数

  • args — 必填 object。
    • amount — 可选 string|number,发票金额,单位为 satoshi。
    • defaultAmount — 可选 string|number。
    • minimumAmount — 可选 string|number。
    • maximumAmount — 可选 string|number。
    • defaultMemo — 可选 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; }

响应

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

示例

const provider = (window.$onekey && window.$onekey.webln) || window.webln; await provider.enable(); const invoice = await provider.makeInvoice({ amount: 1000, });

演示

打开示例 

最后更新于