<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Timothy Masiko</title>
    <description>The latest articles on DEV Community by Timothy Masiko (@timothy_masiko).</description>
    <link>https://dev.to/timothy_masiko</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1012681%2F2ab65fb1-1a0a-43e3-a487-cebea9ebb2c9.jpeg</url>
      <title>DEV Community: Timothy Masiko</title>
      <link>https://dev.to/timothy_masiko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timothy_masiko"/>
    <language>en</language>
    <item>
      <title>Setting Up a Bitcoin and Lightning Network Daemon on Mac from source</title>
      <dc:creator>Timothy Masiko</dc:creator>
      <pubDate>Tue, 31 Jan 2023 01:28:06 +0000</pubDate>
      <link>https://dev.to/timothy_masiko/setting-up-a-bitcoin-and-lightning-network-daemon-on-mac-from-source-17hb</link>
      <guid>https://dev.to/timothy_masiko/setting-up-a-bitcoin-and-lightning-network-daemon-on-mac-from-source-17hb</guid>
      <description>&lt;p&gt;Hey If you are here you might be already interested in getting  yourself set up on this cool Lightning network mission , I found quite a couple of challenges in getting an easy guide to help me get setup much faster so i decided to write this article. Enjoy! &lt;/p&gt;

&lt;p&gt;This guide describes how to build bitcoind (without GUI) and lnd on mac &lt;/p&gt;

&lt;p&gt;This is also heavily based on Michael Goldstein &lt;a href="https://medium.com/@bitstein/setting-up-a-bitcoin-lightning-network-test-environment-ab967167594a" rel="noopener noreferrer"&gt;article&lt;/a&gt; and &lt;a href="https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md" rel="noopener noreferrer"&gt;Bitcoin MacOS Build Guide &lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step one
&lt;/h2&gt;

&lt;p&gt;Update your build tools with the following command from your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xcode-select --install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can skip it incase you are certain your build tools are up to date &lt;/p&gt;

&lt;p&gt;We shall be using brew so ensure you have brew installed on your laptop &lt;/p&gt;

&lt;p&gt;To install the Homebrew package manager, see: &lt;a href="https://brew.sh" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Dependencies
&lt;/h2&gt;

&lt;p&gt;Run the following from your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install automake libtool boost pkg-config libevent

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Clone Bitcoin repository
&lt;/h2&gt;

&lt;p&gt;On the assumption that you have git installed clone the repo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/bitcoin/bitcoin.git

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install additional Dependencies
&lt;/h2&gt;

&lt;p&gt;We shall be using  ZMQ&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install zeromq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ZMQ is automatically compiled in and enabled if the dependency is detected. &lt;/p&gt;

&lt;p&gt;For more information on ZMQ,&lt;a href="//zmq.md"&gt;see&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Bitcoin Core
&lt;/h2&gt;

&lt;p&gt;lets now setup the core , from your terminal cd to bitcoin cloned directory&lt;/p&gt;

&lt;p&gt;run these two commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./autogen.sh
./configure --without-wallet --with-gui=no
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Compile
&lt;/h2&gt;

&lt;p&gt;After configuration, you are ready to compile. Run the following in your terminal to compile Bitcoin Core:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make        # use "-j N" here for N parallel jobs i.e make -j "$(($(sysctl -n hw.physicalcpu)+1))" this gets to speed up the process by usage of the cpu 
make check  # Run tests if Python 3 is available
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running Bitcoin Core
&lt;/h2&gt;

&lt;p&gt;Before running, you need to create  an empty configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p "/Users/${USER}/Library/Application Support/Bitcoin"

touch "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"

chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bitcoin Core should be available at ./src/bitcoind&lt;/p&gt;

&lt;p&gt;You should be able to also access certain other commands like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/bitcoind -daemon      # Starts the bitcoin daemon.
./src/bitcoin-cli --help    # Outputs a list of command-line options.
./src/bitcoin-cli help      # Outputs a list of RPC commands when the daemon is running.
./src/qt/bitcoin-qt -server # Starts the bitcoin-qt server mode, allows bitcoin-cli control
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up Bitcoin
&lt;/h2&gt;

&lt;p&gt;Next, you’ll want to create a configuration file bitcoin.conf that goes our created Bitcoin  directory in Library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;regtest=1
daemon=1
txindex=1
rpcauth=&amp;lt;rpc auth username and password&amp;gt;
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Bitcoin Core to use regtest mode, run as a daemon, and keep an index of all transactions. It also sets up RPC authentication and ZMQ ports for LND to use to communicate with the node. To produce the value to enter for rpcauth, use the script found at ./share/rpcauth/rpcauth.py from the cloned git repository&lt;/p&gt;

&lt;p&gt;run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python rpcauth.py &amp;lt;&amp;lt;username&amp;gt;&amp;gt; // ensure you're are using python3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;copy the rpcauth and password logged we shall use it in our bitcoin.conf file&lt;/p&gt;

&lt;p&gt;Make adjustments to your bitcoin.conf file you can either use nano or a text editor to add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rpcauth=#####
rpcuser=&amp;lt;&amp;lt;username&amp;gt;&amp;gt; // the username you used with the script
rpcpassword= ## password generated with the script

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your bitcoin repository directory&lt;/p&gt;

&lt;p&gt;lets Go ahead and mine a few blocks&lt;br&gt;
run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/bitcoin-cli -generate 5

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Coins are not spendable by miners until there are 100 confirmations, so let’s speed things along with more blocks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/bitcoin-cli -generate 101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should see a positive balance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./src/bitcoin-cli getbalance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bitcoin is up and running!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LND Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s make a directory for our LND nodes. Yes, nodes. We’re going to make two of them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p "/Users/${USER}/Library/Application Support/Lnd

mkdir -p "/Users/${USER}/Library/Application Support/Lnd2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s make configuration files. The first node can use default values, so it will be a simpler file. Save it as lnd.conf in the Lnd directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Bitcoin]

bitcoin.active=1
bitcoin.regtest=1
bitcoin.node=bitcoind

[Bitcoind]

bitcoind.rpchost=localhost
bitcoind.rpcuser=&amp;lt;&amp;lt;username&amp;gt;&amp;gt;
bitcoind.rpcpass=&amp;lt;&amp;lt;generated password from the script&amp;gt;&amp;gt;
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells LND about the Bitcoin node it is using and the RPC and ZMQ details for communicating. Since this is a local test environment, the password is not very secure. If you used a different password in the Bitcoin RPC auth script, be sure to update the value here.&lt;/p&gt;

&lt;p&gt;Now we will make lnd.conf in the Lnd2 directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Application Options]

listen=0.0.0.0:9734
rpclisten=localhost:11009
restlisten=0.0.0.0:8180

[Bitcoin]

bitcoin.active=1
bitcoin.regtest=1
bitcoin.node=bitcoind

[Bitcoind]

bitcoind.rpchost=localhost
bitcoind.rpcuser=&amp;lt;&amp;lt;username&amp;gt;&amp;gt;
bitcoind.rpcpass=&amp;lt;&amp;lt;password&amp;gt;&amp;gt;
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dont forget to replace the username and password&lt;/p&gt;

&lt;p&gt;run this command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s set up some further  aliases on our mac by adding the lines below  in our ~/.zshrc file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export LND1_DIR="$HOME/Library/Application\ Support/Lnd"
export LND2_DIR="$HOME/Library/Application\ Support/Lnd2"

alias lnd1="lnd --lnddir=$LND1_DIR";
alias lncli1="lncli -n regtest --lnddir=$LND1_DIR"


alias lnd2="lnd --lnddir=$LND2_DIR";
alias lncli2="lncli -n regtest --lnddir=$LND2_DIR --rpcserver=localhost:11009"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the adjustments and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check our lightning Node run this in the terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lnd1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;once you're good to go follow up &lt;a href="https://medium.com/@bitstein/setting-up-a-bitcoin-lightning-network-test-environment-ab967167594a" rel="noopener noreferrer"&gt;Running LND&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this is helpful ✨&lt;/p&gt;

&lt;p&gt;Do Like ❤️ &amp;amp; Save 🔖&lt;/p&gt;

&lt;p&gt;Do Follow me here on dev.to ✅ for more Bitcoin Lightning content 👨‍💻&lt;/p&gt;

</description>
      <category>documentation</category>
      <category>community</category>
      <category>discuss</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
