To start using WebLN, you'll need access to the client library. You can either install the package, or include a script. It's highly recommended that you install the package and bundle it rather than relying on an external script.
Install the webln
library using your package manager of choice:
npm install --save webln
yarn add webln
And import it in your project wherever you need it:
import { requestProvider } from "webln";
Alternatively you can include a script in your page that will load the library. Be sure to keep the integrity check to prevent malicious Javascript from loading.
<script
src="https://unpkg.com/[email protected]/dist/webln.min.js"
integrity="sha384-MpjpvOQqXz9nCoLUS/sR0bhLwGYuNPMOBN50jsqhnqAzDq0GiOI0u6oC5fHitzI2"
crossorigin="anonymous"
></script>
This will provide a global WebLN
object in your code, so anywhere you see an import
statement, you can ignore that and access the same code from the global WebLN
object. For instance, the following code:
import { requestProvider } from "webln";
requestProvider(/* ... */);
would instead look like this:
WebLN.requestProvider(/* ... */);
From here, check out how to use requestProvider
and the provider API methods. Make sure you take a look at the source code for each method's demo to fully understand it.