As a contributor to a couple Lightning apps, I went through the tedious process of setting up a local regtest lightning network. This involved downloading bticoind & LND, reading a fair amount of documentation on what command line flags and configuration settings to use to run both in regtest mode. After many hours of trial and error, googling, I finally got the network up and running. Since there's no way I'm going to remember the correct command line flags, I save some bash aliases, for example:

# bitcoind/lnd regtest environment
export LNDREGDIR=$HOME/dev/lnd-regtest
export LNDREGMACDIR=chain/bitcoin/regtest/admin.macaroon

alias brd="bitcoind --datadir=$LNDREGDIR/bitcoin"
alias brc="bitcoin-cli --datadir=$LNDREGDIR/bitcoin"
alias brq="bitcoin-qt --datadir=$LNDREGDIR/bitcoin"

alias lndra="lnd --rpclisten=localhost:10001 --listen=localhost:10011 --restlisten=localhost:8001 --externalip=localhost:10011 --alias=alice --bitcoin.regtest --datadir=$LNDREGDIR/ln-alice"
alias lndrb="lnd --rpclisten=localhost:10002 --listen=localhost:10012 --restlisten=localhost:8002 --externalip=localhost:10012 --alias=bob --bitcoin.regtest --datadir=$LNDREGDIR/ln-bob"
alias lndrc="lnd --rpclisten=localhost:10003 --listen=localhost:10013 --restlisten=localhost:8003 --externalip=localhost:10013 --alias=carol --bitcoin.regtest --datadir=$LNDREGDIR/ln-carol"

alias lnra="lncli --rpcserver=localhost:10001 --macaroonpath=$LNDREGDIR/ln-alice/$LNDREGMACDIR"
alias lnrb="lncli --rpcserver=localhost:10002 --macaroonpath=$LNDREGDIR/ln-bob/$LNDREGMACDIR"
alias lnrc="lncli --rpcserver=localhost:10003 --macaroonpath=$LNDREGDIR/ln-carol/$LNDREGMACDIR"

alias lnrstop="lnra stop && lnrb stop && lnrc stop && brc stop"

Cool, now I have a local Lightning network and some commands I can run to boot it up. But now I want to add a couple more nodes, or test the app against multiple versions of LND, or add c-lightning & eclair nodes into the mix. It just got real! This would require a bunch more aliases, folders to store data, and a lot of trial and error.

The local development environment setup process for Lightning leaves a lot of room for improvement. I want to get started building my app as quickly as possible. The current situation would likely take your average app developer many hours, if not days, to get their own code talking to a running lightning/bitcoin node locally.

I decided to build Polar to allow myself & other developers to get up and running in minutes and not have to touch a command line or config file.

What it does

Polar leverages docker containers for LND & bitcoind to quickly boot up network nodes on Windows, Mac & Linux. Using a graphical interface, developers can:

  • Create one or more regtest Lightning Networks in just a few clicks
  • Connect from your app to the lightning nodes via RPC
  • Add more nodes using drag & drop
  • Open & Close Channels
  • Manually mine new blocks
  • Open a terminal connected to each node to run commands
  • Deposit regtest coins into each Lightning node

How I built it

I started with a basic electron app structure, then added create-react-app with typescript. I then began configuring the docker containers to boot up bitcoind and LND in a regtest environment. Once that was working, I leveraged a react-flow chart library to display a visualization of the network and to allow the user to interact with nodes & channels in the UI. I used the @radar/lnrpc library to talk to the LND nodes over GRPC and the bitcoin-core library to talk to bitcoind nodes. and Throughout this process, I continually added unit tests and e2e tests. I am a big fan of automated testing of an application. Having worked on large projects in the past with no tests, I know what's it's like to lack confidence in making changes, fearful that any small change will break functionality somewhere else in your code. So I wanted to make sure I included tests from the beginning. Along the same lines, I also know how challenging it can be to retrofit multi-language support into an existing application, so I included i18n support from the start. Once most of the application architecture was in place, adding new features like adding nodes and opening channels were pretty trivial.

Challenges I ran into

My biggest challenge is cross-platform testing of the app. I dual-boot OSX & Windows but being able to run my app and test on the different flavors of linux continues to be a burden. I plan to spend more time trying to figure out a way to streamline this process.

Accomplishments that I'm proud of

I'm pretty pleased with the test coverage I've maintained while building the app. It can be a bit time consuming to write tests, but I know it will make my future self a much happier maintainer of the app.

What I learned

There's a lot I've learned about while developing this app. I had no experience with electron, and now I feel pretty comfortable with it's platform. I have previously used docker in a limited capacity. While I wouldn't consider myself an expert, I know much more now about containers, images, networks, etc. than I did before.

What's next for Polar

In future releases, I plan to add support for more lightning node implementations such as c-lightning and eclair. I want to also add a BTC block explorer as well as REST/GRPC API explorers to give the user access to the full RPC interfaces of the nodes. I think a great addition would be to include some tutorial-like content and code for sample apps directly in Polar to help devs get started connecting to their local nodes. I can imagine a developer creating a local Lightning Network and then asking themselves "now what?". There is still much to wrap your head around regarding connecting to the nodes via RPC. I want to close the loop a bit there.

Built With

Share this project: