{"id":381,"date":"2019-02-25T10:47:43","date_gmt":"2019-02-25T10:47:43","guid":{"rendered":"https:\/\/www.usesatoshi.com\/?p=381"},"modified":"2019-03-23T04:13:50","modified_gmt":"2019-03-23T04:13:50","slug":"workshop-1-lightning-node-setup","status":"publish","type":"post","link":"https:\/\/www.usesatoshi.com\/index.php\/2019\/02\/25\/workshop-1-lightning-node-setup\/","title":{"rendered":"Workshop 1 &#8211;  Lightning Node Setup"},"content":{"rendered":"<p>Learning objectives:<\/p><ul class=\"wp-block-list\"><li>to be able to setup a sandbox to learn more about LND<ul><li>what is LND?<\/li><li>what is c-lightning?<ul><li>why the need to install this on top of LND<\/li><\/ul><\/li><li>what are the commands (cli) use for?<\/li><li>what are the use cases for the commands?<\/li><li>how to do up a simple smart contract?<\/li><\/ul><\/li><li>understand what is meant by  <em>programmable <\/em>money<ul><li>give 1 to 2 examples how layer 2 BTC can be used this way<\/li><li>roll out a project to illustrate how layer 2 BTC is used this way<\/li><\/ul><\/li><\/ul><p>Resource materials:<\/p><ul class=\"wp-block-list\"><li><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/bitembassy\/home-node\" target=\"_blank\">Setting up a full Bitcoin Lightning node and wallet<\/a><ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.google.com\/presentation\/d\/1GTCn0uj1EWIMeppk4o0BVdwhx--jbjQDPlrIf2oaXjQ\/edit#slide=id.g4f73e040c7_2_13\" target=\"_blank\">slides<\/a><ul><li>#20: terminal basics<\/li><li>#23: The Onion Router (TOR)<\/li><\/ul><\/li><\/ul><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/dev.lightning.community\/overview\/#lightning-network\" target=\"_blank\">LND Overview and Developer Guide<\/a><ul><li>software components &#8211; <ul><li>lnd &#8211; stands for  Lightning Network Daemon<ul><li>manages a database, connects to peers, opens \/ closes channels, generates payment invoices, sends, forwards, and revokes payments, responds to potential breaches<\/li><\/ul><\/li><li>lncli<ul><li>opens up a command line interface for driving lnd<\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li>alternatively, click  <ul><li><a rel=\"noreferrer noopener\" aria-label=\"c-lightning: A specification compliant Lightning Network implementation in C (opens in a new tab)\" href=\"https:\/\/github.com\/ElementsProject\/lightning\" target=\"_blank\">c-lightning: A specification compliant Lightning Network implementation in C<\/a><\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li>Helpful references<ul><li><a rel=\"noreferrer noopener\" aria-label=\"Understanding the Technical Side of\u00a0Bitcoin (opens in a new tab)\" href=\"https:\/\/medium.com\/@pierre_rochard\/understanding-the-technical-side-of-bitcoin-2c212dd65c09\" target=\"_blank\">Understanding the Technical Side of\u00a0Bitcoin<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"Git (opens in a new tab)\" href=\"https:\/\/try.github.io\/\" target=\"_blank\">Git<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"Programming with Bitcoin Core and Lightning by   Christopher Allen  (opens in a new tab)\" href=\"https:\/\/github.com\/ChristopherA\/Learning-Bitcoin-from-the-Command-Line\/blob\/master\/README.md\" target=\"_blank\">Programming with Bitcoin Core and Lightning by   Christopher Allen <\/a><ul><li>lightning-cli &#8211; <em>work-in-progress<\/em><\/li><\/ul><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"The Bitcoin Lightning Network: A Technical Primer by Joe Kendzicky (opens in a new tab)\" href=\"https:\/\/blog.usejournal.com\/the-bitcoin-lightning-network-a-technical-primer-d8e073f2a82f\" target=\"_blank\">The Bitcoin Lightning Network: A Technical Primer by Joe Kendzicky<\/a> <\/li><li>IDE<ul><li>JetBrains<\/li><li>PyCharm<\/li><\/ul><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"Lightning Network Development for Modern Applications (opens in a new tab)\" href=\"https:\/\/medium.com\/lightwork\/lightning-network-development-for-modern-applications-e4dd012dac82\" target=\"_blank\">Lightning Network Development for Modern Applications<\/a><ul><li>client and server<\/li><li>bitcoin node and lightning network node<ul><li>Bitcoin<ul><li>Bitcoin Core &#8211; bitcoind<\/li><li><del>BTCD &#8211; btcd<\/del><\/li><\/ul><\/li><li>Lightning Network<ul><li>C-Lightning<\/li><li>LND<ul><li>friendly and easy-to-use gRPC\/REST API<\/li><\/ul><\/li><li>Eclair<\/li><\/ul><\/li><\/ul><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"Chaincode Lightning Residency (opens in a new tab)\" href=\"https:\/\/lightningresidency.com\/\" target=\"_blank\">Chaincode Lightning Residency<\/a> <ul><li><a href=\"https:\/\/www.youtube.com\/watch?v=l8OLD7or0DA&amp;list=PLpLH33TRghT1SbxinAsNDS6L7RkAjC8ME&amp;index=11&amp;t=0s\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"the c-lightning API (opens in a new tab)\">the c-lightning API<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li>Working with <strong>lnd<\/strong><ul><li><a rel=\"noreferrer noopener\" aria-label=\"tutorial (opens in a new tab)\" href=\"https:\/\/dev.lightning.community\/tutorial\/\" target=\"_blank\">tutorial<\/a><ul><li><em>requirements: installation of Go, btcd, and lnd on simnet<\/em><\/li><\/ul><\/li><\/ul><\/li><\/ul><p>Exercises: assuming that the setup is completed<\/p><ul class=\"wp-block-list\"><li>Running<ul><li>bitcoind or<\/li><li> bitcoin-qt<br>can run either one (bitcoind ,  bitcoin-qt) <em>not <\/em>both <\/li><\/ul><\/li><li>Test whether bitcoind is running<ul><li>bitcoin-cli getblockchaininfo<\/li><li>ps|grep bitcoind<\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li>shutdown and power up<\/li><li>controlling services<ul><li>Start: sudo systemctl start <\/li><li>Restart: sudo systemctl restart <\/li><li>The services names are: bitcoind,lightningd,btc-rpc-explorer,eps and spark-wallet<\/li><\/ul><\/li><\/ul><p>Questions:<\/p><ul class=\"wp-block-list\"><li>Node address &#8211; does the TOR hide the full node address?<\/li><li>Tor Hidden Services and other &#8211; how to remote access the node and wallet in order to test out cli commands e.g. <\/li><li>Node address does not accept incoming connections &#8211; do we need to open port and <strong>expose <\/strong>IP? &#8211; <ul><li>what abt TOR &#8211; what purpose does it serve?<\/li><\/ul><\/li><li>Test drive commands<ul><li>start <strong><em>lightningd <\/em><\/strong><ul><li>lightning\/lightningd\/lightningd<ul><li>~\/lightning\/cli$ <strong>.\/lightning-cli []<\/strong><\/li><\/ul><\/li><\/ul><\/li><li>lightning-cli help<ul><li>lightning-cli newaddr<ul><li>pay via any segwit HD (hierarchical deterministic) wallet<\/li><\/ul><\/li><li>lightning-cli connect id [host] [port]<\/li><li>lightning-cli getinfo<\/li><\/ul><\/li><li>hands-on example: how to send lightning payments using the terminal?<ul><li>lightning-cli newaddr <ul><li>Layer 1 BTC transaction<\/li><li>Bech32  &#8211;  a segwit address format specified by BIP 0173)<ul><li>bc1 format<\/li><\/ul><\/li><\/ul><\/li><li>lightning-cli listfunds<\/li><li>lightning-cli connect <del>03e5f9d1935c67a029bf0a26af5f63109f4f4c45993a8f45177a8f2f39bcb46144 77.58.162.148 9735<\/del><ul><li>nodeId@host:port<\/li><\/ul><\/li><li>lightning-cli list peers<\/li><li>lightning-cli fundchannel <\/li><li>lightning-cli listpeers<\/li><li>lightning-cli decodepay<\/li><li>lightning-cli pay<\/li><li>lightning-cli listpayments<\/li><\/ul><\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li>Down the rabbit hole &#8230; and took a detour<ul><li>need to take a look into bitcoin-cli and bitcoind, together with chapter 3 of Andreas Antonopoulos&#8217; book Mastering Bitcoin<ul><li>elliptic curve cryptography &#8211;  generating the public key in Python<\/li><li><a rel=\"noreferrer noopener\" aria-label=\"bitcoin scripts (opens in a new tab)\" href=\"https:\/\/bitcoin.org\/en\/developer-guide#p2pkh-script-validation\" target=\"_blank\">bitcoin scripts<\/a><\/li><\/ul><\/li><li>using python to test drive the command-line interface (<strong>cli<\/strong>)<ul><li>see <a rel=\"noreferrer noopener\" aria-label=\"Workshop 1.1 \u2013 Install Python in Ubuntu (opens in a new tab)\" href=\"https:\/\/www.usesatoshi.com\/index.php\/2019\/02\/28\/install-python-in-ubuntu\/\" target=\"_blank\">Workshop 1.1 \u2013 Install Python in Ubuntu<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><ul class=\"wp-block-list\"><li>Back  from the rabbit hole &#8230; to <strong>setup <\/strong>similar environment for writing Lightning Network applications in python<ul><li>c-lightning (Elements Project)<\/li><li>library &#8211; pylightning <ul><li><a rel=\"noreferrer noopener\" aria-label=\"a python client library for lightningd (opens in a new tab)\" href=\"https:\/\/pypi.org\/project\/pylightning\/\" target=\"_blank\">a python client library for lightningd<\/a><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"c-lightning documentation (opens in a new tab)\" href=\"https:\/\/media.readthedocs.org\/pdf\/lightning\/latest\/lightning.pdf\" target=\"_blank\">c-lightning documentation<\/a><\/li><\/ul><\/li><li><a rel=\"noreferrer noopener\" aria-label=\"tool for spinning up a Lightning Network topology for testing and demo'ing LN application (opens in a new tab)\" href=\"https:\/\/www.youtube.com\/watch?list=PLpLH33TRghT2jmuP9YQRo-e8gk969Q2F_&amp;v=U10p0jm8Dx8\" target=\"_blank\">tool for spinning up a Lightning Network topology for testing and demo&#8217;ing LN application<\/a>s<ul><li><a rel=\"noreferrer noopener\" aria-label=\"Lightning Network Development for Modern Applications (opens in a new tab)\" href=\"https:\/\/medium.com\/lightwork\/lightning-network-development-for-modern-applications-e4dd012dac82\" target=\"_blank\">Lightning Network Development for Modern Applications<\/a>  ***<\/li><li><a rel=\"noreferrer noopener\" aria-label=\"lnet -- Simplified Lightning Network Setup (opens in a new tab)\" href=\"https:\/\/github.com\/cdecker\/lnet\" target=\"_blank\">lnet &#8212; Simplified Lightning Network Setup<\/a><\/li><\/ul><\/li><\/ul><\/li><li>First python code<ul><li>Import library\/module<ul><li>from lightning import LightningRpc<\/li><\/ul><\/li><li>Create an instance of the LightningRpc object<ul><li>l1 = LightningRpc(&#8220;\/home\/[username]\/.lightning1\/lightning-rpc&#8221;)<\/li><li>infol1 = l1.getinfo()<\/li><li>print(infol1)<\/li><\/ul><\/li><li>Error messages<ul><li>OSError: [Errno 98] Address already in use<ul><li>sudo lsof -i:8080<\/li><li>kill  &lt;PID&gt;<\/li><\/ul><\/li><\/ul><\/li><li>Additional steps<ul><li>mkdir<\/li><li>pwd<\/li><\/ul><\/li><\/ul><\/li><\/ul><p>[ifpaid 0.00001 BTC text=&#8221;Please pay 0.00001 BTC to continue reading.&#8221; button=&#8221;Click here to pay using the Lightning Network&#8221;]<\/p><ul class=\"wp-block-list\"><li>what is:<ul><li>sudo ufw allow from 192.168.1.0\/24 to any port 50002,3002,9737,22 proto tcp<\/li><\/ul><\/li><\/ul>","protected":false},"excerpt":{"rendered":"<p>Learning objectives: to be able to setup a sandbox to learn more about LND what is LND? what is c-lightning? why the need to install this on top of LND what are the commands (cli) use for? what are the use cases for the commands? how to do up a simple smart contract? understand what [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-lab"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":49,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":556,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/posts\/381\/revisions\/556"}],"wp:attachment":[{"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.usesatoshi.com\/index.php\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}