Actinium’s Lightning Network with LND and Joule-extension

Harris Brakmic
11 min readApr 7, 2019

--

This article describes a step-by-step installation of LND, the Lightning Daemon, and the modified Joule extension that can be used in Actinium’s Lightning Network.

This tutorial applies to Linux and Mac, but it should also be possible to use it for Windows installations.

Installing Prerequisites

To compile LND we must first install the programming language Go’s compiler.

Linux

wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.11.5.linux-amd64.tar.gz

macOS

brew install go@1.11

Now we have to declare paths of those binaries. Open your .bashrc which resides in your $HOME directory and type in the following lines.

export PATH=$PATH:/usr/local/go/bin
export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

Save and close .bashrc then type source .bashrc to activate these changes.

Now create the directory gocode that you declared in .bashrc in your home folder.

mkdir $HOME/gocode

The $GOPATH folder is the place where all of your Go binaries will be located. You don't have to know much about the programming language Go, but in case you are interested visit this page.

Compiling and installing LND

You will now download the latest sources of LND, then compile & install them.

go get -d github.com/Actinium-project/lnd
cd $GOPATH/src/github.com/Actinium-project/lnd
make && make install

The first command above instructs the Go compiler to get the sources from their GitHub location. The second changes your current directory to the one created in your $GOPATH. And the third compiles and installs the binaries within $GOPATH.

You will have to wait for a while for the compiler to download all needed dependencies.

Check your LND installation

Before you begin setting up your LN node first check for the existence of lnd and lncli. If your compilation was successful the two commands below would present you the paths to them (both are located in $GOPATH of course).

which lnd
which lncli

Take care of running the legacy version of Actinium!

As LND needs certain RPC commands only available in our legacy version you should take care of running this version of our wallet. It is recommended to use the latest BETA that won’t reindex the local copy of your chain, because it’s compatible with the current NG variant. macOS users can download the DMG while Linux users would have to compile it. There is a detailed tutorial on compilation under Linux available.

Start the Actinium wallet

You can use the UI or the daemon to sync with Actinium’s blockchain

$ /path/to/Actinium-qt &

or

/path/to/Actiniumd -datadir=/path/to/blockchain-directory-with-Actinium.conf

Writing configuration file for LND

As there are many different ways to run a LN-node you must write a proper configuration file located in ./lnd/lnd.conf. However, in most cases you will be able to copy the file below and only adapt the node's name, color and maybe ports if you are not using the defaults. macOS users will have to change the root paths from ~/.lnd/ to ~/Library/Application Support/Lnd/. The data-subdirectories are the same and must not be changed!

However, do not blindly copy this configuration file and read its comments! Some of the entries must be set in your Actinium.conf as well, like ZMQ ports and RPC user/password data.

[Application Options]
debuglevel = info
maxpendingchannels=5
no-macaroons = false
alias = YOUR_LND_NODE_NAME
color = #AABBCC
datadir = "~/.lnd/data"
adminmacaroonpath = "~/.lnd/data/chain/actinium/mainnet/admin.macaroon"
readonlymacaroonpath = "~/.lnd/data/chain/actinium/mainnet/readonly.macaroon"
invoicemacaroonpath = "~/.lnd/data/chain/actinium/mainnet/invoice.macaroon"
tlscertpath="~/.lnd/tls.cert"
tlskeypath="~/.lnd/tls.key"
nat = false
; Specify the interfaces to listen on for gRPC connections. One listen
; address per line.
; Only ipv4 localhost on port 10009:
; rpclisten=localhost:10009
; On ipv4 localhost port 10009 and ipv6 port 10010:
rpclisten=localhost:10009
rpclisten=[::1]:10010
; On an Unix socket:
; rpclisten=unix:///var/run/lnd/lnd-rpclistener.sock
; Specify the interfaces to listen on for REST connections. One listen
; address per line.
; All ipv4 interfaces on port 8080:
; restlisten=0.0.0.0:8080
; On ipv4 localhost port 80 and 443:
restlisten=localhost:8080
restlisten=localhost:8443
; On an Unix socket:
; restlisten=unix:///var/run/lnd-restlistener.sock
[Actinium]
actinium.mainnet = 1
actinium.active = 1
actinium.node = actiniumd
[autopilot]
autopilot.active = 1
autopilot.maxchannels = 10
autopilot.allocation = 0.6
; Actiniumd + ZMQ settings
; This means that your node must have ZMQ compiled, which is by default the case.
; Don't forget to add the same ZMQ settings in your Actinium.conf
[Actiniumd]
actiniumd.rpchost = localhost:2300
actiniumd.rpcuser = YOUR_ACTINIUM_WALLET_RPC_USER
actiniumd.rpcpass = YOUR_ACTINIUM_WALLET_RPC_PASSWORD
actiniumd.zmqpubrawblock=tcp://127.0.0.1:28332
actiniumd.zmqpubrawtx=tcp://127.0.0.1:28333

Running LND

Type in lnd in your console and press ENTER. You will get a similar message:

LND initialization output

The LND daemon has started and now waits for the user to unlock (or create a new) wallet. This wallet btw. is not the one you are using in your Actinium client. LND maintains a separate wallet within its $HOME/.lnd directory. You should take great care of it and treat it just like any other cryptocurrency wallet! Especially the macaroon files that you'll find there as well. Those files function almost like private keys and allow anyone who has access to them to execute every function and control your funds.

Creating a new LND wallet

Having said that now let’s create a new LND wallet by executing lncli which provides the interface to the LND daemon. First, open a new shell session as the current one is blocked by LND itself, and leave it there as it is.

lncli create

The above command will start a new session in which you will setup your new wallet. At the end you will get a 24-word seed that you must store safely. Without it you won’t be able to restore your funds in case of emergency!

Unlocking LND wallet

Having successfully created a new LND wallet you can now unlock it with the password you entered during its creation.

lncli unlock

Now switch to the console where LND is still waiting. You will see new entries scrolling as the synchronization process has kicked in after you have entered the correct password. Wait a bit until LND has reached the tip of Actinium’s blockchain.

Funding LND wallet

To participate in Actinium’s Lightning Network you will have to send some funds to your LN-node first. For this use lncli to generate a new bech32, also called native segwit, address:

lncli newaddress p2wkh

You will get an address similar to this one:

Getting a new address for LND

You will now send some funds to this address from your Actinium wallet, or if you are running the daemon send them with Actinium-cli. Here’s an example on how to send 10ACM.

Actinium-cli sendtoaddress "acm1q9q533ra3h86sve3mq2wrqvdme5hczl69ytu9lp" 10

You will have to wait for confirmations before you can use those funds. Check the availability with:

lncli walletbalance
`

For some time the balances will be shown as unconfirmed_balance but ultimately they will be shown as in the image below:

Checking balances

Opening a channel and funding it

With a confirmed balance you are now able to open and fund channels to other Lightning Network nodes. The easiest way to find other nodes is by using one of our Lightning Explorers:

Click on any of the available nodes and take its ID and IP address. In rare cases you’d also have to note the port number if the node isn’t using the default LN-port 9735. Also, some of the nodes are private and not showing their IP address. Those won’t be available for setting up new channels.

Here an example of a selected node that is reachable (note the green dot below the node name on the right sidebar):

Actinium’s Lightning Explorer

The yellow arrow points at the Node ID and the green arrow points at Node’s IP address and port. You will need the first two entries as the port is Lightning Network’s default one. In cases when a node isn’t following the defaults you’ll also have to copy the port. Now let’s open a connection to this node:

lncli connect lncli connect 0202226a224ccd28c11b3355a16b5469c6bdad1acff5ed0f9c21e2d035a49e6d44@89.22.110.186

Note the @ between Node ID and IP address. You must include it.

The output of the connect command will be an empty message containing brackets:

Connecting a Lightning Node

We’re now ready to open and fund a Lightning Network channel with it. Here we declare that we want to fund it with 10ACM (written in satoshis) and the — node_key value is the same Node ID we used previously to connect with it.

lncli openchannel --node_key 0202226a224ccd28c11b3355a16b5469c6bdad1acff5ed0f9c21e2d035a49e6d44 --local_amt 1000000000

The success will be confirmed with the funding transaction ID we can search for in one of our explorers:

Channel successfully funded

After the funding transaction has been confirmed we will be able to participate in the Lightning Network. But having only a single peer connected isn’t enough so we should try to connect more nodes. The more channels we have the greater the chance to calculate the best route for our next payment (or invoice). But doing the same operation again and again is a bit tedious. Luckily, there is an option to automatically open multiple channels. In our above lnd.conf example you can see that the option autopilot has been activated. This functionality allows your node to automatically establish several channels so that you don't have to do everything manually. When you list all known peers with lncli listpeers you will see several entries and not only the one you just opened.

Listing peer information

Paying an invoice

Let’s now try to pay an invoice with our node. For this go to our Lightning Shop and select one of the articles.

Actinium’s Lightning Demo Shop

A Lightning invoice will appear whose bolt11 string you should copy (this is the long alphanumeric string of characters that begins with lnacm1).

A shop invoice

We can decode this request to see what’s inside.

Decoding the payment request

If we agree with the payment request our next step will be to use lncli to invoke a command for paying invoices by providing it this bolt11 string as parameter.

lncli payinvoice --pay_req lnacm193564990p1pw2ns0upp5d78s2zjtkxvrwyg59kfghqzara6034y4v0h3zsw7clsajsqsu4aqdpjg93hg6twd96k6gzvd9nksarwd9hxwgzndphhqw3qvdhkven9v5xqzjhcqp28jrnctvwymxx98xqscuh7vrz5ht07whmhnxcpcel96wk94js36c3s6d6y8tuqh9uke5htznvhh8g22gfwg5h75umzw8u058mgrzt3xcqv7ukls

We will be asked by lncli if we really want to send the requested sum which we answer with yes. The result of our action will be similar to the output below. However, as routing in Lightning Network changes rapidly expect some very different outputs in your case.

Paying an invoice and subsequent results

The most interesting information in this rather complex block of data is surely the term hops that indicates the route your paymend had to take to arrive at its destination. In this case the payment didn't go directly from your node to Lightning Shop's node but instead over a third node that didn't participate in the payment itself but only functioned as relay. And as those services are not for free you had to pay a certain routing fee written at fee_msat (fee in milli-satoshi). The more hops a payment needs the more fees it'll have to pay. The full sum is shown at total_fees_msat.

Congratulations!

You just bought some coffee in Actinium’s Lightning Network. 👍

Making your LN-life easier by using Browser extensions

However, despite all the exciting stuff you just witnessed one thing is unavoidable: you have to be experienced and patient enough to use the command line. Command line tools are powerful of course, but what most users need are easy-to-use tools and not raw power. One such tool is the joule browser extension that was originally developed for Bitcoin and Litecoin. In the following text we will use a variant of it that was ported to Actinium but still retains compatibility with Bitcoin. If you happen to be running a Bitcoin LN node in parallel you’ll be able to use it for both of the coins.

Joule browser extension with Actinium support

The source code of this extension is located here, but you don’t have to build it yourself as a precompiled zip-file is available from our home page. Unpack this file into a folder and then open Chrome extension tab by typing chrome://extensions in the address bar. As this extension is not available in the official Chrome AppStore you must activate the Developer Mode by clicking the slider on the right in the same tab.

activating the developer mode in Chrome browser

Now click the button Load unpacked on the left and point to the folder where your unpacked files reside. The Joule extension will appear in the list.

Installed joule extension

You will also see the Actinium logo in the extension list to the left of the browser’s address bar. Click on it to start the configuration.

The first configuration question will be the type of the node you are running. In our case it’s a local node.

Selecting the LN node type

You’ll have to enter the local REST-API which is usually at https://localhost:8080 (you can also find it in your lnd.conf. For example: restlisten=localhost:8080).

Providing the REST-API URL

The next step will be providing the paths to admin and readonly macaroons. As already mentioned at the beginning of this article those files are extremely important and have almost the same power as Private Keys. So, do not keep them around except in your .lnd respective Lnd folders.

Uploading macaroons

The you’ll confirm your node.

Confirming own node

The last step will be creating a new password.

Setting up a new password

Congratulations!

You have successfully installed and configured your Joule extension with Actinium compatibility.

Joule extension window

Now let’s try to buy that coffee again, shall we? ☕️

We go back to our shop, select a product and push the button Send in Joule. Now instead of manually entering all the commands all we have to do now is to copy/paste the bolt11 into the box in Joule and push the Send button below.

Paying with Joule extension

You will be asked for the password and if everything’s ok the result would look like this:

Payment successful

This is it! You can now use your Lightning Node without ever having to touch the command line.

Have fun with the Lightning Network! 😎

--

--