jamaljsr / polar

One-click Bitcoin Lightning networks for local app development & testing
https://lightningpolar.com
MIT License
771 stars 145 forks source link

Advice for developing with Polar #503

Closed izz-j closed 3 years ago

izz-j commented 3 years ago

Hey so I'm playing around with the default nodes (Alice, Bob, etc). I have a project on my host system that I would like to interact with the Alice Lightning node container. Basically, I'm trying to integrate lncli commands to manage payments for Alice node container from my host system. I'm doing this cause I don't want to run my entire project directory and editor (emacs) in a docker container. This is probably more of a docker question than polar, but nevertheless, I feel I could get good advice here.

jamaljsr commented 3 years ago

You can connect lncli and your app to the Polar nodes. You just need to use the host, cert, and macaroon displayed on the Connect tab.

The lncli command would look like this:

lncli --rpcserver=127.0.0.1:10001 --tlscertpath=~/.polar/networks/1/volumes/lnd/alice/tls.cert --macaroonpath=~/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon

Note: Change the values based off your network and node

izz-j commented 3 years ago

Thank you for the quick response. Would I need to run this command from the host? That would require me to download and install lncli on my host system right?

jamaljsr commented 3 years ago

I may have misunderstood your original question. I thought you were asking how to connect from lncli to the Polar nodes.

If you are trying to connect from an app to the nodes, you just need to use the host, cert, and macaroon info displayed on the Connect tab. Take a look at the sample app walkthrough here for a guide. I hope this helps. If not, can you rephrase your question?

izz-j commented 3 years ago

Sorry, yes I will rephrase. I have a project I am working on in my home directory (Debian). I want my code to interact with the polar nodes. How can I go about this?

Thank you again for your swift replies.

jamaljsr commented 3 years ago

Ah ok. Connecting your app to LND nodes in Polar depends on what programming language and application framework you are using. As a start, I would recommend taking a look at the sample app walkthrough which is written in Typescript. There's also a companion video that goes through this guide as well.

In addition to that, I would also recommend taking a look at the Resources page in the Builder's Guide. There are links to dev tools, libraries, as well as links to additional lists of resources.

Hope this helps.

izz-j commented 3 years ago

Ah ok thank you for these resources I will check them out! My project is written in Common Lisp, but I am calling shell commands with it as well. So essentially I planned on calling lncli commands with lisp.

jamaljsr commented 3 years ago

Oh if you going to call lncli commands from your app, then you'll just need to use the flags I mentioned in https://github.com/jamaljsr/polar/issues/503#issuecomment-944016198 when executing the command. You will need to install lnd and lncli on your machine. You can just download the binaries for your OS or compile from source.

izz-j commented 3 years ago

Yes exactly! Ok I see sorry for the confusion. I just grabbed those binaries! Thank you. How do I make the lnd binary use the bitcoin backened node in Polar? Cause when I run it, its looking for bitcoind.

jamaljsr commented 3 years ago

You don't need to run lnd if you are using the Polar LND nodes. They are already running lnd and connecting to the Polar bitcoind nodes. All you need to do is start the Polar network, get the connection info from the Connect tab, then run lncli using the command line args mentioned above. With this setup, your app uses lncli on your host to connect to lnd in Polar which connects to bitcoind in Polar.

izz-j commented 3 years ago

It seems when I run the command you mentioned. It just sends me to the help menu. But when I run lncli I get this:

[lncli] could not load global options: could not load TLS cert file: open /home/izz/.lnd/tls.cert: no such file or directory

To me it looks like the global setting still needs to be overridden. Cause by default lncli is looking for the cert in my home directory as soon as it runs. I copied alice's TLS cert to my home directory to appease it but then I get the same error but this time looking for the admin.macaroon file. I'm thinking there must be a better way to get this to work..

jamaljsr commented 3 years ago

The command I sent is incomplete, it only includes the config arguments needed to connect to the Polar lnd node. You have to append the subcommand that you want to execute, for example getinfo or listchannels. You may also need to change the port or paths based on your local Polar network. View the Connect tab for the correct values.

izz-j commented 3 years ago

oh wow :man_facepalming: I'm embarrassed for that one. Thank you again. That was all of my questions. It's working for me now.

jamaljsr commented 3 years ago

It's all good. Best of luck with your app.