đ¨âđģđ¨đģ Getting Started
Installation
Browsers with WebLN capabilities provide APIs using a global JavaScript variable window.webln
that can be used to interact with the connected Bitcoin Lightning wallet.
You don't need to add any library to your project.
Detecting WebLN support
Before you start using WebLN you need to check for browser support by checking if the variable window.webln
is defined:
if (typeof window.webln !== 'undefined') {
console.log('WebLN is available!');
}
window.webln
might not be available during pageload. See the code example below for proper detection.
Enable WebLN
Before you can work with any of the WebLN APIs you need call the method enable()
:
await window.webln.enable();
Depending on the used WebLN provider this will ask the user to connect their Lightning wallet with the website.

Using WebLN
Now you are ready to work with the WebLN APIs.
await window.webln.enable();
await window.webln.sendPayment();
Have a look at the the WebLN Reference for detailed explanations and usage examples for the different APIs.
WebLN Events
WebLN triggers events like webln:enabled
upon enabling, allowing apps and packages to subscribe and listen to these events.
window.addEventListener("webln:enabled", () => {
console.log("WebLN is enabled!");
});
Error handling
There are different errors that can happen while using the WebLN APIs. Make sure to handle them and let the user know what went wrong.
Error handlingLast updated