Type definitions for WebLN
- Install package
npm install @webbtc/webln-types --save-dev # or yarn add @webbtc/webln-types --dev
- Type definitions are now available through
window.webln
and 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:
/// <reference types="@webbtc/webln-types" />
Read the WebLN Guide