<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Lightwork - Medium]]></title>
        <description><![CDATA[Lightning Network Development - Medium]]></description>
        <link>https://medium.com/lightwork?source=rss----56eed60fb0e9---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Lightwork - Medium</title>
            <link>https://medium.com/lightwork?source=rss----56eed60fb0e9---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:52:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/lightwork" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lightning Network Development for Modern Applications]]></title>
            <link>https://medium.com/lightwork/lightning-network-development-for-modern-applications-e4dd012dac82?source=rss----56eed60fb0e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/e4dd012dac82</guid>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[lightning-network]]></category>
            <category><![CDATA[reckless]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[application-development]]></category>
            <dc:creator><![CDATA[André Neves]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 03:15:36 GMT</pubDate>
            <atom:updated>2018-11-19T03:15:20.538Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>In-depth guide to help you kickstart and streamline your Lightning Application development workflow</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvmkfDX42IMkDCN3JYalUQ.png" /></figure><h3>Introduction</h3><p>I had the privilege to participate in the <a href="https://lightningresidency.com/">Chaincode Labs Lightning Residency 2018</a>, along with 11 other amazing Lightning Network (LN) enthusiasts from around the globe. We learnt about deep technical concepts regarding the BOLTs specifications and went into detail about the various node implementations available to date, their advantages and disadvantages.</p><p>We were also tasked with building an application — extension, plugin, web app, mobile app, you name it. Throughout that week, while building the first version of the <a href="https://www.lightwork.app/">Lightwork</a> web application, I encountered some architectural issues, mostly relating to the handling of BOLT11 invoices (core to LN) between the LN node and my web app. Having gone through (most of) these hurdles, I figured I’d write about the major pain points about developing an LN-powered application and how to mitigate them.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLpLH33TRghT2jmuP9YQRo-e8gk969Q2F_&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIRusrbbaGCI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIRusrbbaGCI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/aff8e846d83bea4cc23686a8ffa557f3/href">https://medium.com/media/aff8e846d83bea4cc23686a8ffa557f3/href</a></iframe><h3>Application Stack</h3><p>There are usually two main entities to most modern applications: a Client and a Server. The Client can be a mobile application or a JavaScript SPA for example, and the Server can be comprised of a NodeJS/Go/Rust backend, which exposes a RESTful or GraphQL-based API.</p><p>Adding Lightning Network support for your application, will usually introduce two new entities to your application stack: a Bitcoin node and a Lightning Network node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uU_hAeVVOnFxvZJlYVu7Nw.png" /><figcaption>Over-simplified representation of an LN-powered application stack</figcaption></figure><p>For Bitcoin there are a couple node implementations available to use, with the two most widely accepted ones being:</p><ul><li><a href="https://bitcoincore.org/">Bitcoin Core</a> — bitcoind</li><li><a href="https://github.com/btcsuite/btcd">BTCD</a> — btcd</li></ul><blockquote>Based on community consensus, number of active nodes on the network, and maintenance stats from the respective code repositories, it’s clear that Bitcoin Core is the most widely used and better-maintained implementation — and the one we’re going to use.</blockquote><p>On the Lightning Network side of things, there are (currently) three compatible clients that all adhere to the same BOLT specifications:</p><ul><li><a href="https://github.com/ElementsProject/lightning">C-Lightning</a> (written in C)</li><li><a href="https://github.com/LightningNetwork/lnd">LND</a> (written in Go)</li><li><a href="https://github.com/ACINQ/eclair">Eclair</a> (written in Scala)</li></ul><p>You should evaluate each of the clients and decide what makes the most sense for you. I’ve personally used C-Lightning and LND before, but have also heard great things about the Eclair client. For <a href="https://www,lightwork.app/">Lightwork</a> I decided to go with LND as it provides a friendly and easy-to-use gRPC/REST API, as well as Neutrino light client support out-of-the-box (testnet for now).</p><p>Time to get our nodes up and running.</p><h3>Bitcoin Core Setup</h3><p>The current <em>mainnet</em> Bitcoin blockchain sits at roughly ~260GB of data with around 550,000 blocks mined. Since our LND node depends on having access to the underlying chain for opening and closing channel transactions, running a full node on <em>mainnet</em> in a local machine/laptop seems like a huge undertaking. Not only is it 1/4TB of data, but it also takes a couple hours to fully sync (depending on your connection it can take many days).</p><p>Bitcoin also has a <em>testnet3</em> network, which allows for developers to test new features and changes to the protocol without affecting <em>mainnet</em>. This is also great for developers building applications and services upon Bitcoin, which are able to test end-to-end flows using valueless <em>testnet</em> BTC coins. The <em>testnet</em> is lighter in size, sitting at around ~25GB with roughly 144,000 blocks. Syncing <em>testnet3</em> still seems like a big hurdle if all you want to do is mess around with an application that interfaces with the Lightning Network. That is why Bitcoin Core gives us yet another network, this one called <em>regtest</em> (<em>simnet</em> for btcd users).</p><p><em>Regtest</em> is a version of the blockchain that you essentially start from scratch on your machine. Given that its sole purpose is to allow for faster development on the protocol, as the admin of that node, you can mine as many blocks as you need (almost) instantaneously. And the best part is that it’s only as large of a chain as you make it. I’ve used my <em>regtest</em> network extensively when developing and it still sits at ~37MB. This is more along the lines of what we want.</p><h4>Installing Bitcoin Core Node</h4><blockquote>These following instructions are for running bitcoind on macOS systems. For Windows and Linux instructions, please see <a href="https://bitcoin.org/en/full-node#windows-instructions">https://bitcoin.org/en/full-node</a></blockquote><p>If you haven’t already, install Bitcoin Core on your environment by running:</p><pre>curl -O <a href="https://bitcoin.org/bin/bitcoin-core-0.17.0/bitcoin-0.17.0-osx64.tar.gz%60">https://bitcoin.org/bin/bitcoin-core-0.17.0/bitcoin-0.17.0-osx64.tar.gz</a></pre><p>If you are familiar with PGP, it’s also advised that you check the signed hash for the release: 01EA 5486 DE18 A882 D4C2 6845 90C8 019E 36C2 E964 (more info <a href="https://bitcoin.org/en/full-node#windows-instructions">here</a>).</p><p>Now you can unpack the tarball with:</p><pre>tar -zxf bitcoin-0.17.0-osx64.tar.gz </pre><p>And subsequently make the bitcoind binary available system wide with:</p><pre>sudo mkdir -p /usr/local/bin <br>sudo cp bitcoin-0.17.0/bin/bitcoin* /usr/local/bin/</pre><p>To clean things up you can delete the downloaded folder with:</p><pre>rm -rf bitcoin-0.17.0*</pre><p>You should now have full access to using the bitcoind and bitcoin-cli commands on your machine.</p><h4>Node Configuration</h4><p>A Bitcoin Core full node has many configuration options, so instead of passing all of these parameters on the command line every time you run the binaries, it is advised that you use a bitcoin.conf config file.</p><blockquote>For a list of all commands supported by bitcoind run bitcoind --help .</blockquote><p>Below is an example of a config file with the (necessary) parameters to run a <em>regtest </em>node (and connect to an LND node):</p><pre># Daemon Options<br>server=1</pre><pre># Network Options<br>regtest=1</pre><pre># RPC Options<br>rpcport=8332<br>rpcuser=USERNAME_HERE<br>rpcpassword=PASSWORD_HERE</pre><pre># ZMQ Options<br>zmqpubrawblock=tcp://127.0.0.1:28332<br>zmqpubrawtx=tcp://127.0.0.1:28333</pre><p>To keep things simple, you could create your bitcoin.conf file in the main Bitcoin folder that’s created in your system by the full node. In macOS systems, that folder is located at ~/Library/Application Support/Bitcoin.</p><blockquote>Make note of the RPC username and password you choose as we’ll need it during the LND node configuration.</blockquote><p>You can then run the following to step into that same Bitcoin directory and start your node daemon with the newly created configuration file:</p><pre>cd ~/Library/Application Support/Bitcoin</pre><pre>bitcoind -datadir=./ -conf=./bitcoin.conf</pre><p>You should see an output similar to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3DJXD90BZMszwN3cizJ8_Q.png" /><figcaption>Note that the logs mention <strong>regtest</strong> many times</figcaption></figure><p>In a separate terminal window, you can run bitcoin-cli getblockchaininfo and you will see the latest data sets from your <em>regtest</em> Bitcoin chain, including the current block height, difficulty level and size on disk. For a full list of bitcoin-cli commands, run bitcoin-cli --help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*url2Yhb0AMQ8arE4imVYDg.png" /><figcaption>Regtest blockchain info</figcaption></figure><p>When you run bitcoind for the first time, it automatically creates a wallet for you. So at this point, any BTC earned through mining rewards will be sent to this wallet. To mine <em>regtest</em> blocks simply run bitcoin-cli generate 100, where 100 is the number of blocks to be mined. If you run bitcoin-cli getwalletinfo you’ll now have a value under ‘balance’. These are <em>regtest</em> BTC coins that are perfect for testing Lightning Network applications. Now that we have a Bitcoin Core daemon running and we know how to mine <em>regtest</em> blocks, it’s time to setup our LND nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*V-zRldQUEDIHaE5Mo1XLqw.png" /><figcaption>10 blocks mined</figcaption></figure><blockquote>You will most likely need to mine upwards of 100 blocks in the beginning of your regtest network in order to see mining rewards appear in your wallet.</blockquote><h3>LND Node(s) Setup</h3><p>To connect to the Lighting Network, all you need is an LND node connected to an underlying chain. However, in order to send funds around the network, you must have another node to send to, or request from. One approach would be to spin up multiple VPS boxes with different Bitcoin Core and LND nodes, and then open channels between the two. A simpler approach would be to have multiple LND instances running in your machine, connected to a single <em>bitcoind</em> <em>regtest</em> node that you have full control over. A user can run as many LND nodes they’d like in a single environment, there are only three requirements:</p><ul><li>Each node must have its own dedicated data directory</li><li>Each node must have its own gRPC/REST ports</li><li>Each node must have its own set of TLS certificates and admin macaroons</li></ul><p>LND creates all of the necessary data files needed to run a node on startup, including the authentication macaroon files. With that in mind, after spinning up the first node, you can simply clone it (and delete the authentication macaroons/TLS certs so they’re recreated on initialization of the second node). For macOS users, the default LND folder is at ~/Library/Application Support/Lnd (<strong>NODE A</strong>), so I just cloned it into ~/Library/Application Support/Lnd Test(<strong>NODE B</strong>).</p><blockquote>You may place your node data directories wherever in your file system. This is not a requirements for the nodes to function properly.</blockquote><h4>Node Configuration</h4><p>Similar to Bitcoin Core, the LND node takes in a configuration file known as lnd.conf. In order to run two nodes, we’ll need two files, placed inside each of the respective data directories, configuring the nodes to connect to the correct bitcoind instance.</p><p><strong>NODE A</strong> will be running on the default data directory and the default settings (RPC/REST/gRPC ports). We’ll use the following conf file:</p><pre># <em>LND Settings</em><br>debuglevel=debug<br>debughtlc=true<br>alias=YOUR_NODE_NAME<br>maxpendingchannels=10<br>color=<em>#eeeeee<br></em>rpclisten=0.0.0.0:10009<br>restlisten=0.0.0.0:8080<br>listen=9735<br>externalip=127.0.0.1:9735<br>datadir=./<br>datatlscertpath=./tls.cert<br>tlskeypath=./tls.key<br>adminmacaroonpath=./data/chain/regtest/admin.macaroon</pre><pre># Bitcoin<br>bitcoin.active=1<br>bitcoin.regtest=1<br>bitcoin.node=bitcoind</pre><pre># Bitcoind<br>bitcoind.rpcuser=USERNAME_HERE<br>bitcoind.rpcpass=PASSWORD_HERE<br>bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332<br>bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333</pre><blockquote>Note that the ZMQ options and the RPC username and passwords must match the previously configured bitcoind.conf settings.</blockquote><p><strong>NODE B</strong> will have essentially the same configuration settings, apart from the connecting ports. More specifically, the rpclisten, restlisten, listen, and externalip properties all receive new ports.</p><pre># <em>LND Settings</em><br>debuglevel=debug<br>debughtlc=true<br>alias=YOUR_NODE_NAME<br>maxpendingchannels=10<br>color=<em>#eeeeee<br></em>rpclisten=0.0.0.0:10008<br>restlisten=0.0.0.0:8090<br>listen=9736<br>externalip=127.0.0.1:9736<br>datadir=./<br>datatlscertpath=./tls.cert<br>tlskeypath=./tls.key<br>adminmacaroonpath=./data/chain/regtest/admin.macaroon</pre><pre># Bitcoin<br>bitcoin.active=1<br>bitcoin.regtest=1<br>bitcoin.node=bitcoind</pre><pre># Bitcoind<br>bitcoind.rpcuser=USERNAME_HERE<br>bitcoind.rpcpass=PASSWORD_HERE<br>bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332<br>bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333</pre><p>At this point we have two LND nodes running on different data directories, with their own set of TLS certs and authentication macaroons, and running on/against different ports. Time to start the network. In two separate terminal shells, start both <strong>NODE A</strong> and <strong>NODE B</strong> with:</p><pre>lnd --configfile=./lnd.conf</pre><p>In two more shells, use the lncli tool to send commands to your nodes. Run the following to create a wallet. For <strong>NODE A</strong>, we simply need to run the create command, like so:</p><pre>lncli --network=regtest create</pre><p>For <strong>NODE B</strong>, we must pass a few more properties:</p><pre>lncli --network=regtest --rpcserver=localhost:10008 --lnddir=./ --tlscertpath=./tls.cert create</pre><p>The added properties are to ensure that the second lncli call is talking to <strong>NODE B </strong>running on port 10008. Run through the wallet creation process and create yourself a password for each of the wallets.</p><blockquote>Note that once you’ve created your wallet, you can simply run the unlock command to get things going.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jp0yt36qLz7vQy2of45duA.png" /><figcaption>LND Node 1 on the left and LND Node 2 on the right</figcaption></figure><p>There is a whole lot that an LND node actually does, and to learn all of its capabilities head over to <a href="https://github.com/lightningnetwork/lnd">LND’s docs</a> or run lncli --help to see a couple of the commands. A few of the more widely used ones are:</p><pre># Wallet balance, in Satoshis<br>lncli walletbalance</pre><pre># Balance of all channels combined, in Satoshis<br>lncli channelbalance</pre><pre># Generate Invoice<br>lncli addinvoice --amt=1000 --memo=testing</pre><pre># Pay Invoice<br>lncli payinvoice lnbcrt10u1pdlyp6fpp50xvlxjg...</pre><pre># Connect to specific node URI<br>lncli connect 03fbe39af6166273...@127.0.0.1:9735</pre><pre># Open channel with to specific node <br>lncli openchannel 03fbe39af6166273...1af2 100000</pre><p>We’ll use each of these commands to send LN invoices between our two nodes, but before we do that we need some actual <em>regtest</em> BTC in one of our wallets.</p><h4>Sending <em>regtest</em> BTC from Bitcoin Core to LND node</h4><p>You can use the bitcoin-cli tool to send mined <em>regtest</em> BTC to <strong>NODE A</strong>. First generate a new address from inside <strong>NODE A</strong>:</p><pre>lncli --network=regtest newaddress np2wkh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dRStVZrQe4vIl3Vpk2Yxpg.png" /></figure><p>Then head on over to Bitcoin Core and send some <em>regtest</em> BTC to that address. Make sure to generate a couple blocks to mine and confirm the transaction.</p><pre># Send 250 BTC to the LND Address<br>bitcoin-cli sendtoaddress 2MuKLyJQn2UQ2BaVotWpCKAfXpkrsa96eL7 250</pre><pre># Mine Blocks<br>bitcoin-cli generate 10</pre><p>Now, back in <strong>NODE A</strong>, we can get our wallet balance and see that our BTC has transferred correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tonc1EYUCj8DCigtOzCpLA.png" /></figure><h4>Opening channel between the two LND nodes</h4><p>Now that we have BTC inside of <strong>NODE A</strong>, we can <strong>get NODE B </strong>to create some payment requests for <strong>NODE A</strong>. As part of the Lightning Network specification, nodes need to have channels open with other nodes if they’d like to send and receive satoshis (routing invoices through other indirect nodes is of course possible in a real network scenario, just not in our <em>two-node LND regtest</em> network).</p><p>To connect two nodes you need to get the node’s public URIs. On <strong>NODE B</strong>, run the following command:</p><pre>lncli --network=regtest --rpcserver=localhost:10008 --lnddir=./ --tlscertpath=./tls.cert getinfo</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvF-k5W3-o--SLdD52UMEw.png" /></figure><p>The highlighted portion is the URI that we’ll need to use to connect to this node. If you don’t see a URI listed, it’s probably because you don’t have the externalip property set on your LND configuration files.</p><p>To open a channel between the nodes, first we need to connect them. Run the following on <strong>NODE A</strong>, with <strong>NODE B</strong>’s URI.</p><pre>lncli --network=regtest connect 0394ed661ff...92f446@127.0.0.1:9736</pre><p>We still have no channels opened, so even if we were to try and pay an invoice, we’d run into routing issues:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mep3KFh7NDemGtA0Qx1IKg.png" /><figcaption>Routing issue on LN payment request</figcaption></figure><p>As part of opening a channel, LND will create a funding transaction onchain, setting an amount of satoshis to lock in this newly created channel.</p><pre>lncli --network=regtest openchannel NODE_PUB_KEY amount</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Oo2O5vCu1jrwNwUxJGFNA.png" /><figcaption>Opening channel in LND</figcaption></figure><p>For the funding transaction to be valid, you will need to run bitcoin-cli generate 10 in order to mine a couple more blocks in Bitcoin Core. At this point you can run listchannels inside <strong>NODE A</strong> to see the opened channel between the two nodes:</p><pre>lncli --network=regtest listchannels</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TOw1olNIvCoDLDzNDlyZwQ.png" /><figcaption>List of opened channels with LND node</figcaption></figure><h4>Handling Invoices (BOLT11 Payment Requests)</h4><p>Now that <strong>NODE A</strong> has been funded with some <em>regtest</em> BTC, and we have an active opened channel between the two nodes, we can create an invoice to transact some BTC.</p><p>Invoices are at the center of any Lightning Network transaction. To learn more about LN Invoices (Payment Requests) and the BOLT11 specification, <a href="https://medium.com/lightwork/development-tooling-for-invoices-in-lightning-network-applications-cf3d194dc2bb">read my other article on it</a>.</p><p>From <strong>NODE B</strong>, generate an invoice for 300 satoshis, with a description of ‘testing’:</p><pre>lncli --network=regtest --rpcserver=localhost:10008 --lnddir=./ --tlscertpath=./tls.cert addinvoice --amt=300 --memo=testing</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8r4PyP7noUCRUYFvopjSmQ.png" /></figure><p>The highlighted portion is the BOLT11 Payment Request hash. To learn a little more about this invoice, and the types of data we can decode from it, head on over to <a href="https://lightningdecoder.com/">Lightning Decoder</a> and paste your invoice in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTKBnjaAY0Ysxs1atKRYgg.png" /><figcaption>BOLT11 Decoder — <a href="https://lightningdecoder.com/">https://lightningdecoder.com</a></figcaption></figure><p>From <strong>NODE A</strong>, we can pay this newly created invoice, and have the payment routed over the Lightning Network through the channel we have just opened.</p><pre>lncli --network=regtest payinvoice lnbcrt3u1pdlygj221k0x...c0h503tpr</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jy3p57h4jY_TBDuSZePqMA.png" /></figure><p><strong>NODE B</strong> should now have 300 satoshis listed on its side of the channel. We can check it with the channelbalance command.</p><pre>lncli --network=regtest --rpcserver=localhost:10008 --lnddir=./ --tlscertpath=./tls.cert channelbalance</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CZGpBjzzm_L9MrtDiU_Hbg.png" /></figure><p>Lo’ and behold, our 300 satoshis have been transferred.</p><p>You have successfully connected two LND nodes running on the same <em>regtest</em> BTC network, opened a channel between them, and transacted BTC through the payment of BOLT11 invoices. With this setup, you can create endless real-world scenarios of payments through these two LND nodes. This will allow for much easier testing, iteration and troubleshooting of the backend server logic of your Lightning Network-powered application.</p><p>Now, to interface with the node from within your application, look into <a href="https://api.lightning.community/">LND’s gPRC or RESTful APIs</a>. You may also leverage an abstraction layer such as <a href="https://github.com/alexbosworth/ln-service">LN Service</a> by <a href="https://twitter.com/alexbosworth">Alex Bosworth</a>, which may provide a friendlier API.</p><h3>LNET</h3><p>When developing LN apps, it’s common to follow a <em>regtest</em> → <em>testnet</em> → <em>mainnet</em> approach, but depending on your application size and requirements, it might make sense to add an extra step.</p><p>On the last day of the Chaincode Lightning Residency 2018, <a href="https://github.com/cdecker">Christian Decker</a> from <a href="https://blockstream.com/">Blockstream</a> demo’ed lnet. The goal behind lnet is to simplify the process of initializing a LN network topology for application testing. All you need to do is describe the network in the <em>graphviz</em> dot format, and lnet will take care of the rest. This library was built upon C-Lightning instead of LND and does not (yet?) provide as much control, customization and configuration as spinning up your own nodes — but it does facilitate testing with lots of nodes.</p><p>More info here:<a href="https://github.com/cdecker/lnet"> https://github.com/cdecker/lnet</a></p><h3>Conclusion</h3><p>I’ll continue to share notes like these as I continue to develop <a href="https://www.lightwork.app/">Lightwork</a> and further my understanding of the Lightning Network. In the next post I hope to walk through actual code snippets/implementations that were used to build Lightwork’s support for LN payments and withdrawals — real world source code is more valuable than 1000 words.</p><blockquote>Hashtag Reckless</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4dd012dac82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lightwork/lightning-network-development-for-modern-applications-e4dd012dac82">Lightning Network Development for Modern Applications</a> was originally published in <a href="https://medium.com/lightwork">Lightwork</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Development Tooling for Invoices in Lightning Network Applications]]></title>
            <link>https://medium.com/lightwork/development-tooling-for-invoices-in-lightning-network-applications-cf3d194dc2bb?source=rss----56eed60fb0e9---4</link>
            <guid isPermaLink="false">https://medium.com/p/cf3d194dc2bb</guid>
            <category><![CDATA[invoice]]></category>
            <category><![CDATA[development-tools]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[lightning-network]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[André Neves]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 15:08:51 GMT</pubDate>
            <atom:updated>2018-11-08T15:09:37.937Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tooling for Invoices in Lightning Network Applications</h3><p><a href="https://lightningdecoder.com/">Lightning Decoder </a>— the first of (hopefully) many development tools</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gm21SiVtL0vJZ0BF" /><figcaption>Lightning Decoder — <a href="https://lightningdecoder.com/">https://lightningdecoder.com</a></figcaption></figure><p>Throughout my quest of bringing <a href="http://www.lightwork.app/">Lightwork</a> to production on Bitcoin’s mainnet, I’ve come across some gaps in the current development workflow of Lightning Network-powered applications. One of the larger gaps I saw was in relation to the use and understanding of the Invoice Protocol (<a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md">BOLT11 spec</a>), which is core to the network.</p><blockquote>The Invoice Protocol is a simple, extendable QR-code-ready protocol for requesting payments over the Lightning Network.</blockquote><h3>BOLT11 Encoding</h3><p>Sometimes referred to as a <em>Payment Request</em>, the format for a Lightning Network invoice uses a <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki">bech32 encoding</a>, which is also used for Bitcoin’s Segregated Witness.</p><p>The creator of an LN invoice must encode the payment request in bech32 as specified in <a href="https://en.bitcoin.it/wiki/BIP_0173">BIP-0173</a>. The only exception is that the bech32 string can be longer than the 90-character limit specified in the BIP. The receiver of an LN invoice must parse the address as bech32 (without character limit), and must fail if the checksum of the hash is incorrect.</p><h3>Invoice URI Scheme</h3><p>For applications that need to interface with LN Payment Requests, it is recommended to use a lightning: prefix , followed by the BOLT11 invoice encoding, as such:</p><pre>lightning:lnbcrt5u1pdam80cpp5hrx4jp3hwe0vrl3jyft95fnfvgsvc327xw5j63mfchc6nazl87csdphf35kw6r5wahhy6eqx43xgepev3jkxctyxumrjdrxxqmn2ctrve3njvscqzys9htkyg7r5kesumuhkntta8syzc2uclqj2lrq5spwppa2r4d2dm49pkhpjemjp3rrm0se4cmakcqgrakpk9hlnv2mgj3dus3yujfzhqsqa7satk</pre><blockquote>Note, it’s not lightning:// but just lightning: .</blockquote><p>Given that Lightning payments can sometimes fail (due to routing or capacity issues), application developers should also have fallback support for moving transactions onchain. For that, one should leverage the bitcoin: URI scheme, as per <a href="https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki">BIP-21</a>, with the key lightning and the value equal to the BOLT11 invoice encoding.</p><h3>Lightning Decoder</h3><p>Though one might be able to understand (or even memorize) the BOLT11 specification, it is usually pretty hard to reason about the many bits of information that make up a single Lightning Network invoice. This is where Lightning Decoder comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gm21SiVtL0vJZ0BF" /><figcaption>Lightning Decoder — <a href="https://lightningdecoder.com/">https://lightningdecoder.com</a></figcaption></figure><p><a href="https://lightningdecoder.com/">Lightning Decoder</a> is meant to be a one-stop solution for your Lightning Network invoice-decoding needs. It’s where you can decode payment requests and learn all of the information bits involved in its creation. This is key to not only understand how this payment request came about, but also to drill into the details of the payment to ensure parity with your application’s own database of records.</p><p>Below is an example of an invoice being decoded through Lightning Decoder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*DkZ7YhMgm9vdUQd6R3p2TQ.png" /><figcaption>Decoded Lightning Network Invoice — https://lightningdecoder.com</figcaption></figure><p>It provides clear information about which underlying chain this invoice was created in/for, what the desired payment amount is (in satoshis), as well as a timestamp of its creation. This also helps in identifying payee public node keys, transaction signatures and payment hashes which can be verified further.</p><h4>LN Node &amp; Application State Sync</h4><p>In lieu of keeping your application state and your Lightning Network node in sync it is common to follow a redundant architectural approach, where each database document holds an array of its relevant LN invoices (expired or not), and each LN invoice holds a version of the ID of the database document it belongs to.</p><p>For Lightwork I decided to leverage the ‘description’ field. This is a blank field in the LN payment request that allows for the user to input any text/data/string (similar to a memo field). After being encoded, that information is invisible to the naked eye. But when decoded you see something along the lines of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*tEmVh0sdKna68x6KGq4baQ.png" /><figcaption>Description field for LN invoice inside Lightwork — https://lightningdecoder.com</figcaption></figure><p>My approach is to enter an identifier string, in this case Lightwork which allows me to split the string precisely and predictably. The following 5bdd9d… is the ID of the database document this invoice belongs to. This make is easier to connect an LN invoice to its related document when subscribing to payments over the network. I’ve personally heard this approach being used in other applications that accept Lightning payments, which is even further validation of this implementation.</p><h3>UX for Development Tools</h3><p>Most application developers tend to be versed in command line applications, and are usually okay using tools that provide sub-optimal user experiences, since they tend to be merely a utility rather than an end product on its own. As an daily user of development tools, I tend to disagree that they can forego (all) decent UX, simply because ‘engineers are tech-savvy and don’t need pleasant products to achieve their implementation goals’.</p><p>My goal with Lightning Decoder was to bring pleasant design and utility together, so that developers can not only depend on its functional capabilities, but can also enjoy the experience of using and relying on it daily.</p><p>This is the first of (hopefully) many tools that I’ll be deploying as I continue my efforts in building <a href="http://www.lightwork.app/">Lightwork</a>. I have already outlined a couple of other gaps in the LN development workflow that seem to allow for the creation of other tools like this. <a href="https://github.com/andrerfneves/lightning-decoder">Lightning Decoder is entirely open source</a>, and I aim to introduce new features and capabilities as the Lightning Network continues to evolve and mature.</p><p>Cheers,</p><blockquote>Hashtag Reckless</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf3d194dc2bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lightwork/development-tooling-for-invoices-in-lightning-network-applications-cf3d194dc2bb">Development Tooling for Invoices in Lightning Network Applications</a> was originally published in <a href="https://medium.com/lightwork">Lightwork</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>