btclnfrst - A Bitcoin Lightning Experiment

May 28, 2019

Introduction

Bitcoin Lightning Forest (btclnfrst) is an experiment in accepting Bitcoin Lightning Network payments to plant trees in a virtual forest.

I was curious about the difficulty in setting up a Bitcoin Lightning Payment gateway, to learn about how Lightning Network (LN) functions, and what the challenges are.

If you are unfamiliar with the Lightning Network, it’s a “micropayments protocol that enables instant, low-cost Bitcoin transactions”.

You can find more information here: https://blockstream.com/lightning/.

How it works

btclnfrst runs on the Bitcoin TESTNET, which can be used to test Bitcoin (and Lightning) applications.

This app is similar in functionality to Starblocks, where you can buy pretend coffees using Lightning on TESTNET. However, in contrast to Starblocks, you can actually see the result of your “purchase” when you plant your trees in the shared virtual forest.

The workflow is straightforward and similar to any online shopping website:

Add items to your cart → Proceed to checkout → Make payment → Use your purchase.

Making the payment and seeing your trees being planted is the interesting part.

I have deployed my own Lightning node on a Digital Ocean droplet, and wrote a small server than uses RPC calls to the LN node to create payment requests and subscribe to payments (if there’s any interest in this I will can share it with pleasure).

If you are interested in setting up your own Lightning Node, I highly recommend this guide by Stadicus. It is for a Raspberry PI but can easily be adapted to another type of Linux Host.

Choosing your trees

I have implemented 4 types of trees with arbitrary prices in SAT (SAT = Satoshis, where 1 SAT = 1/100 000 000 BTC, or 100 000 000 SAT = 1 BTC). Lightning is for micropayments so SAT is a common unit:

Shopping cart

Checkout

When you choose “Checkout”, it will take you to the payment page:

Shopping cart

What happens behind the scenes is that a “payment request” for a specific amount and destination is generated. In this case for 2850 SAT, and the destination is my Lightning node. This information is encoded in the payment request:

lntb28500n1pww6tkzpp5cawjzql5zu0xjttepnh7dh5x82n8ruas2nxf8zp36h3z4qr9cf5sdpdwphhqmrpwg7nqgr0v94n6dfqve5hy0fjypkkzurvv57nzcqzpg7p9hehpcd6vrlqmfna0enl3yhechjy6wuuaw08uw7z3dfx3suu0xg5adgwww4w6l9jwnt2wu8wdgage9fyx4ydyz2g7edquumls8jgcqmpfpkg

Once you have a payment request, there are two useful websites where you can send TESTNET Bitcoin using Lightning:

https://htlc.me or http://lnd.fun/pay

The payment request can also include a memo. I have included the cart contents in the memo. If you use lnd.fun and click the “decode” button you can see the amount and memo:

Shopping cart

If you’re using another node and need to connect to my payment node as a peer or open a channel, the address is:

03cf07ccd645ef88a9451b06df30e3d5b076347901583183b1df5876521e39c0ff@188.166.133.145:9735

Payment & planting

My app will then subscribe to events on my Lightning node to wait for a payment. Once payment is received you can proceed to planting your trees:

This is a shared forest and it will show in real-time then other users plant trees:

Challenges

The Lightning Network is a very interesting concept, with a lot of potential for small BTC payments. Bitcoin is just too slow and expensive to buy things like coffee.

Lightning requires you to create channels to other nodes and fund these channels (on the Bitcoin blockchain), so you must ensure you create channels to receive payments. This is known as inbound liquidity and there are way to obtain it, e.g. How to get Inbound Liquidity on LN.

Setting up your own LN node is not trivial and quite technical, as you need to set up a BTC node and an LN node. If popularity grows I expect to see more LN wallet providers to come to market, both for consumers and merchants.

Then there are alternative hybrid micropayments alternatives (e.g. SPEDN by Flexa) which might prove more popular with consumers and merchants.

Conclusion

The Lightning Network is still in its infancy, but has the potential to be the “cash” of Bitcoin (queue a flamewar 🔥).

I encourage you to try my app and also to experiment with LN - money can actually be fun.