grubles
grubles
Jul 2, 2019 · 5 min read
Image for post
Image for post

This guide is for building and using c-lightning on the Liquid sidechain to create Lightning payment channels. With these payment channels, users can transact Liquid-BTC (bitcoin transferred to the Liquid sidechain) instantly and privately.

Support for Confidential Transactions and Issued Assets is planned, so users will be able to transact any asset issued on the Liquid Network in a Lightning payment channel — such as tokenized fiat, crypto assets, attested assets (e.g. gold coins), or completely new assets. Also, support for swapping on-chain BTC for L-BTC in a payment channel is being worked on.

Using c-lightning on Liquid is practically the same procedure as using it on the Bitcoin mainnet, so if you’re familiar with that then the steps here will be easy to follow (although they’re fairly easy regardless :-)).

Sections

Installing the required software

Running lightningd

Opening a Lightning payment channel

Transacting L-BTC via a Lightning payment

Closing the payment channel

Contributing to c-lightning

Requirements:

A synced Bitcoin node (latest Bitcoin Core)

A synced Liquid node (latest release)

c-lightning

Ubuntu 18.04.2 LTS

Installing the required software

To begin, a synced Bitcoin node and an Elements node synced to the Liquid chain are required to open Lightning payment channels on the Liquid sidechain.

Follow these guides to get each running:

Installing Elements

(For Elements, add chain=liquidv1 to elements.conf to sync to Liquid)

Installing Bitcoin Core

Once both nodes are synced, make sure you have all of the dependencies, then grab the lightning-elements branch from Christian Decker’s Github repository.

Install dependencies:

Download the lightning-elements branch:

Build the code:

Now there should be Elements / Liquid-compatible binaries in their respective directories, including lightningd/lightningd and cli/lightning-cli .

Running lightningd

lightningd provides a --network argument to choose which blockchain one wants to run on, such as the Bitcoin mainnet, testnet, regtest, and so on. The lightning-elements branch also supports the liquid sidechain, so let’s use that option to get started.

$ ./lightningd/lightningd --network liquid ... <other arguments>

This will sync to the Liquid sidechain and start running.

Opening a Lightning payment channel

Now we can begin funding an address in order to open a Lightning channel. Simply use lightning-cli to generate a p2sh-segwit address and send it some L-BTC.

To acquire Liquid-BTC (L-BTC), either obtain some from a Liquid member exchange such as Bitfinex, The Rock Trading, or shapeshift.ai, or perform a peg-in manually by following this guide.

Generate the p2sh-segwit address:

Fund that address with some L-BTC, then connect to a Liquid Lightning peer.

(For this guide / demo, a peer running on the local network is used)

connect public_key@ip_address:port

The peer will be shown with the listpeers command.

The L-BTC transaction will have confirmed by now due to the fast settlement times on the Liquid sidechain (1–2 minutes).

As shown in bold, the output is 0.00100000 L-BTC.

Open a channel

Now that an address is funded with some L-BTC, initiate a channel opening.

fundchannel <peer id> <amount in satoshis>

The amount can also be all to use all available L-BTC in the wallet.

The text output after entering that command will be the transaction hex, ID, and the channel ID.

The channel will then be shown in listpeers as ”state” : “CHANNELD_AWAITING_LOCKIN” .

listpeers will show “CHANNELD_NORMAL:Funding transaction locked.” after 3 Liquid blocks (3 minutes).

Now the Lightning channel is open!

Transacting L-BTC via a Lightning payment

Now that a channel is open to a peer on the local network, we can generate a Lightning invoice and send an L-BTC micropayment.

Generate an invoice

The arguments for invoice are as follows:

invoice msatoshi label description

In this example, an invoice for 1 millisatoshi of L-BTC with the label “test1” and description “testing lightning on liquid” is created on the receiving node. The invoice itself is a long string of seemingly random numbers and letters beginning with ln .

Decoding the invoice

On the sending node, use decodepay to decode the bech32 Lightning invoice.

Finally, pay the invoice

On the sending node, use pay to pay the 0.00000000001 L-BTC.

The "status" : "complete", shows that the payment is complete and the invoice is paid!

Closing the payment channel

Feel free to send L-BTC back and forth between your nodes. After you’re done testing and want to close the channel, follow these steps.

On one of the nodes, initiate a cooperative channel closing by issuing a close command with lightning-cli .

$ ./cli/lightning-cli close <channel id>

This will submit a closing transaction on-chain and the channel will be closed.

Contributing to c-lightning

If you’re interested in contributing to c-lightning or Elements / Liquid development, feel free to check out the code on Github and join #c-lightning and #sidechains-dev on Freenode to chat with Blockstream engineers and other independent developers.

Thanks for reading!

Blockstream Engineering Blog

The latest developments in cutting-edge Bitcoin technology…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store