pull down to refresh

First Bounty!
I’m looking for what you think the simplest way to talk to a Lightning Node from a JavaScript frontend for all the plebdevs out there.
It took me quite awhile as a junior developer to get to the point where I was meaningfully interacting with Lightning, I want to discover the easiest path for the Bitcoin plebs learning how to code to be able to do the same. Share your experience and expertise!


When replying, please make sure to:
  1. Explain why your recommended method is the easiest
  2. Mention any tradeoffs or potential limitations associated with your method
  3. Provide example projects or guides (if available) to help others implement your suggestion

Thank you in advance!
12,000 sats paid
bitcoinplebdev's bounties
I would suggest LNbits.
LNBits acts as a very thin layer on top of many possible funding sources (LND, CLN, Ecliar, another LNBits, ... You can check the full list here). It's fully open-source, trivial to set up, has some of the brightest and nicest minds working on it.
Useful features:
  • Supports multiple accounts. This means you can abstract away from the funding source, which is a single LN node that only has one balance, and support as many users as you want with it. This is how the well known telegram LightningTipBot works.
  • Exposes API endpoints for all typical operations (generate invoices, pay invoices, check balances, etc). So, easy to hit from your JS code.
  • LNbits comes with a ton of extensions that also implement API endpoints. These expand the possibilities way beyond the simple LND node features. This might save you more coding in your front-end.
You don't even need to deploy it yourself if you want to test it out. There is an open access, fully functional demo server maintained by the core team that you can use to play around. You can easily jump into your own instance once you need that (or be a bit irresponsible and stay on the demo server. You won't be the first one to do that :) ).
You can find a curated collection of projects that are built on top of LNBits here: https://github.com/cryptoteun/awesome-lnbits#software-projects-utilizing-lnbits. The page also contains good learning resources.
And regarding tradeoffs and limitations:
  • It's early, and it's beta. Things might be shaky at first.
  • The URL-based security turns-off many people. It is a polemic trade-off between security and convenience. You must decided if it suits your needs.
You can check the docs here.
Hope this helps. I'm personally in love with LNbits.
reply
Incredible LNBits shill! I love it but a bit of work on the API docs would go a long way for the plebs who are getting their hands dirty with Lightning for the first time. Still LNBits is super powerful with all of the extensions and a must learn for anyone wanting to build Lightning apps.
A close second place for the bounty, thank you for the great response!
reply
No probs, good luck with the development and come back to show us when you've built something cool.
reply
Alby + WebLN provides easy access to lightning nodes from a JavaScript frontend.
  1. As a developer, you don´t need to implement different interfaces for each lightning node implementation. Developers can easily access any node API without having to deal with the complexities of connecting to the node or the underlying protocol. Loading the lightning channels from LND is just a function call: webln.request('listchannels') (example for LND) No macaroons, no gRPC or other additional software package needed to build a web app. Users can bring their own node connection to web applications without having to pass their node credentials, without installing additional node software or having to jump loops to access nodes behind Tor. You can find more details in this blog post
  2. As a developer you can stay completely in JavaScript but you would need to adjust the naming of the call to each implementation API (e.g. webln.request('listchannels') for LND or webln.request('listpeers') for CLN if you want to load lightning channels of a specific node). With increasing demand that will become more consistent, I guess.
  3. Examples: Node management dashboard for LND and Liquidity Ad marketplace
reply
Congrats my friend!
I do have to agree after working with Alby / WebLN this past week it has without a doubt been the easiest way to start building a simple lightning app while still exposing the full API for LND/CLN. I've also been using Polar with NGROK to do development in regtest and it's been super easy.
Love what you all are doing, thanks for the thoughtful response!
reply
Yeay, glad you like it. Thanks so much for the bounty and all the work you do with plebdevs. So important.
reply
I recently was search for the easiest way to do this, not with JS, but from within Android. I managed to get a MVP (GPT4BTC) communicating with getalby's LN node via their lnurl REST api: example Android Kotlin code.
  1. By far the easiest solution is to simply use a third-party's api (i.e. getalby.com) to interact with LN via lnurl protocol, as you won't have to deal with setting up and maintaining your own node. For example, payRequests allow you to call REST api to get encoded ln invoice, as in example below.
  2. The trade offs are, of course, loss of control, placing trust in third-parties, and limitations of their api. Also there are serious limitation with the lnurl specs themselves. For example: there are limited extra data fields you can pass into invoices, such as 'amount', 'comment', 'name', and 'email' - although the spec will no doubt expand its capabilities overtime.
  3. Here's some simple restful uri examples for interacting with getalby lnurl api from a web context - where 'bitanon' is my lnurl address username on getalby: bitanon@getalby.com.
-get lnurl details, including default human-readable payment meta-data: https://getalby.com/.well-known/lnurlp/bitanon
-get encoded lnurl from 'pr' field, including amount and comment (description): -note: unfortunately invoice details returned seem to remain encoded when viewed in sending wallet https://getalby.com/lnurlp/bitanon/callback?amount=10000&comment=hello
Certain wallets also allow for passing in other payRequest payerData.
Now, I'm learning how to use lnauth, hopefully in a similar manner, owing to the ease of implementation; and will reply to this post in the future with details on how to do that.
reply
Also, response includes 'verify' field containing a url for verifying if payment was successfully received!
reply
Whatever this thing does. https://reckless.mutinywallet.com/
But also like, do you want to do this? Its one thing to make a pwa bundled into a sandboxed application encrypted data at rest and all those other software practices, but its another thing to load something like this into google chrome where the user might have some browser extension installed that either messes the app or is malicious out the gate and steals funds
(I use as a singular example but just scroll through the CVE list. Browsers struggle to be secure)
reply
Hell yeah, the progress on Mutiny has definitely WASM pilled me just need to get more familiar with it. Also Mutiny is using a rust BE that they're compiling for the FE so it might be pretty difficult to work with that without a decent amount of backend/rust experience.
reply
I would say setup LNBits and interact with that API. It can be used with any lightning node pretty much so your front end can be used for multiple projects.
There are lots of plugins for different things that all have APIs by default. You could also make a new plugin if you need something that isn’t available.
I don’t know if any guides for this but that’s my best suggestion. About to start working on this myself and it’s the best solution I could think of.
reply
Awesome! Yeah I did an example project recently with a nextJS app talking to LNBits deployed with voltage. The setup is really easy but the LNBits API can be pretty hard to navigate especially with extensions added on (maybe I'm just a noob though)
reply
Assuming you are using a browser and not an app:
  1. Do it through a custom backend or adapt the CORS headers in order for the browser.
  2. You main problem will be securing the authentication tokens/credentials, specially for the later approach.
  3. You could use https://github.com/Ride-The-Lightning/RTL as inspiration.
reply