webln-types
Type definitions for WebLN
WebLN may be implemented by a lightning browser extension (e.g. Alby) therefore WebLN can already be called directly from the browser if the user has the extension installed. This package simply adds type definitions to make it easier to integrate WebLN into web applications that are written in Typescript.
Quick Start
- Install package
npm install @webbtc/webln-types --save-dev
- Type definitions are now available for
window.webln
and by importing from "@webbtc/webln-types"
import { GetInfoResponse } from "@webbtc/webln-types";
if (window.webln) {
(async () => {
await window.webln.enable();
const info: GetInfoResponse = await window.webln.getInfo();
console.log("Your node pubkey is", info.node.pubkey);
})();
} else {
console.warn("WebLN not enabled");
}
If you do not import any types from "@webbtc/webln-types" and just want to use window.webln, add the following line somewhere in your codebase (e.g. the main/index.tsx file) to ensure the types still get consumed:
Adding WebLN to your application
Read the WebLN Guide