On this page
Guide
Overview
This guide helps users understand how to build Bitcoin Lightning Network applications using the OneKey Lightning Network Provider API.
Building Web Apps Use Cases
- Accepting Lightning Network payments
- decentralized identity applications
Install
1. Download OneKey Wallet
Download the OneKey Wallet . Install the OneKey browser extension.
2. API Injection Explanation
- The OneKey browser extension injects
Provider APIinto visited websites. - Two types of APIs are provided:
window.weblnandwindow.$onekey.webln. - It is recommended to use
window.$onekey.webln.
Prefer
window.$onekey.weblnto select OneKey specifically. The globalwindow.weblnmay belong to another wallet when multiple extensions are installed.
Detecting Provider API support
Check that a provider is available before making requests:
const provider = (window.$onekey && window.$onekey.webln) || window.webln;
if (!provider) {
throw new Error("No provider is available.");
}Connecting to OneKey
Before using the following API, you first need to use the provider.enable method to request the user to access the relevant account.
const provider = (window.$onekey && window.$onekey.webln) || window.webln;
await provider.enable();Other APIs can be called only after user authorization.
API
Choose an API for the operation your application needs.
- Get user’s Bitcoin Lightning node information:
provider.getInfo - Send a payment:
provider.sendPayment - Request an invoice to receive payment:
provider.makeInvoice - Request signature for any message:
provider.signMessage
More Interfaces: View Details
Event
- Key Operations: Such as account switching
- More Information: View More
Handling requests
Run wallet requests from an async function or an ES module. Catch rejected promises and show the error in your application. Request connections, signatures, and payments from a user action, and disable the triggering button while a request is pending.