Browsing all articles in Bitcoin

Raspberry Pi - Palm of your Hand

The Lightning Network is Bitcoin’s biggest step in achieving global performance and scalability. To truly achieve scale in the billions of transactions per day, you need what’s called “off-chain” transactions, and the Lightning Protocol lays out exactly how it’s done.

This guide walks you through the steps in running a full Bitcoin Lightning Network node on a Raspberry Pi. When you’re finished, you’ll have a full-featured, decentralized international bank in the palm of your hand contributing to world commerce! How cool is that?

 

 

There’s 4 steps to getting this done:

1. Setting up your Raspberry Pi
2. Compiling and configuring a Bitcoin full node, syncing the blockchain, and adding your node to the Internet
3. Compiling and configuring a Lightning Node, and broadcasting its existence to the Internet
4. Funding your wallet

Plow through these steps, and you’ll soon be up, running and doing your part in making Bitcoin and the Lightning Network bigger and stronger!

1. Raspberry Pi Setup

Raspbery Pi SetupFirst, you need a Raspberry Pi and an External USB drive with at least 250GB (as of the time of this post) capacity. I found an old, slow 250GB USB 2.0 drive lying around. It doesn’t have to be super fast – it’s more about storage than speed.

Install Raspian and enable SSH. Follow this guide for detailed instructions.

Once you’re up and running, it’s always a good idea to update to latest packages:

pi@raspberrypi:~$ sudo apt-get update
pi@raspberrypi:~$ sudo apt-get upgrade
pi@raspberrypi:~$ sudo apt-get dist-upgrade
pi@raspberrypi:~$ sudo apt-get autoremove

Next, you need to mount your USB drive. The MicroSD card should be used for the operating system and programs only, not for the large and growing Bitcoin blockchain. I recommend formatting the drive as NTFS, but you can also use native Linux EXT4. One of the main reasons you may want to use NTFS, is that if you want to download the blockchain faster, you could download it via a Windows full node, and then use the drive for the Raspberry Pi. For details on other options, here’s a detailed guide. For this example below, it assumes you’ve formatted the drive as NTFS. Plug your drive into your Raspberry Pi. Now you’ll install NFTS on Raspberry Pi and mount it.

pi@raspberrypi:~$ sudo apt-get install ntfs-3g

Confirm that the drive is recognized:

pi@raspberrypi:~$ sudo fdisk -l

At the bottom of the partion list, you should see something like this:

Device Start End Sectors Size Type
/dev/sda1 2048 625072127 625070080 298.1G Microsoft basic data

‘/dev/sda1’ is your mount point. Create a mount point and mount the disk:

pi@raspberrypi:~$ mkdir data
pi@raspberrypi:~$ sudo mount /dev/sda1 /home/pi/data

To ensure it’s mounted each time you reboot, edit /etc/fstab:

pi@raspberrypi:~$ sudo vi /etc/fstab

and add this line:

/dev/sda1 /home/pi/data ntfs-3g rw,default 0 0

Now you will be able to see the contents of the drive:

pi@raspberrypi:~$ ls data
drwxrwxrwx 1 root root 0 Mar 18 22:44 $RECYCLE.BIN
drwxrwxrwx 1 root root 0 Mar 18 20:47 System Volume Information

Great! Now our Raspberry Pi is setup, we’ve got the latest-and-greatest updates, and enough disk space to host a full node. On to Step 2.

2. Compile, configure, sync, and broadcast a full Bitcoin node

First, install the pre-requisites needed to compile and run Bitcoin.

pi@raspberrypi:~$ sudo apt-get install git build-essential autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev libtool libzmq3-dev libevent-dev libtool libssl-dev libboost-all-dev libminiupnpc-dev qt4-dev-tools libprotobuf-dev protobuf-compiler libqrencode-dev db4.8-util -y

There’s more… Download, compile, and install Berkeley DB:

pi@raspberrypi:~$ wget http://download.oracle.com/berkeley-db/db-4.8.30.zip
pi@raspberrypi:~$ unzip db-4.8.30.zip
pi@raspberrypi:~$ cd db-4.8.30
pi@raspberrypi:~/db-4.8.30$ cd build_unix
pi@raspberrypi:~db-4.8.30/build_unix$ ../dist/configure --prefix=/usr/local --enable-cxx
pi@raspberrypi:~db-4.8.30/build_unix$ make
pi@raspberrypi:~db-4.8.30/build_unix$ sudo make install
pi@raspberrypi:~db-4.8.30/build_unix$ cd ~

Let’s update all packages again just to ensure we have latest and greatest.

pi@raspberrypi:~$ sudo apt-get update
pi@raspberrypi:~$ sudo apt-get upgrade
pi@raspberrypi:~$ sudo apt-get dist-upgrade
pi@raspberrypi:~$ sudo apt-get autoremove

OK, let’s download Bitcoin and build it. As of this post, Bitcoin is on version 0.16. Change the branch name (-b) below to the latest version.

pi@raspberrypi:~$ git clone -b 0.16 https://github.com/bitcoin/bitcoin.git
pi@raspberrypi:~$ cd bitcoin/
pi@raspberrypi:~bitcoin$ ./autogen.sh
pi@raspberrypi:~bitcoin$ ./configure
pi@raspberrypi:~bitcoin$ make
pi@raspberrypi:~bitcoin$ sudo make install

Be prepared to wait. This may take at least 2 hours!

Now that you’ve got Bitcoin downloaded, compiled, and installed, the next step is to RUN it. First, cd into your USB drive and let’s make a bitcoin.conf file:

pi@raspberrypi:~$ cd data
pi@raspberrypi:~/data$ mkdir BitcoinData
pi@raspberrypi:~/data$ cd BitcoinData
pi@raspberrypi:~/data/BitcoinData$ vi bitcoin.conf

Add these lines (change the rpc password, this is just an example):

server=1
daemon=1
txindex=1
rpcuser=bitcoinrpc
rpcpassword=ysSDnfRcSTCmI0syEwrM67brd8QnPc12pkKyFLtU
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28332

Add a symbolic link for ~/.bitcoin. This makes it easy to run bitcoin-cli commands without having to specify a specific -datadir each time.

pi@raspberrypi:~/data/BitcoinData$ cd ~
pi@raspberrypi:~$ ln -s /home/pi/data/BitcoinData/ ~/.bitcoin

Start the Bitcoind daemon to run the node:

pi@raspberrypi~$ bitcoind -daemon

Nice! We’re off and running. Let’s check the progress of the node as it downloads the blockchain. It’s gonna take a while. Depending on your bandwidth, it could take a few days – if not more. Eat. Sleep. Code. Repeat. Wait this out…

Patience, you must have

While you’re waiting, you can check progress by looking at the ‘progress’ output. Once it hits 1.0, you’re synced!:

pi@raspberrypi~$ tail -n 1 ~/.bitcoin/debug.log
pi@raspberrypi~$ bitcoin-cli getblockchaininfo

Allow the pi user to run tasks at startup:

pi@raspberrypi~$ sudo vi /etc/cron.allow

Add this line:

pi

Create a bash file to start the Bitcoin Daemon on reboot:

pi@raspberrypi~$ vi bitcoin-start.sh

With this:

#!/bin/bash
sleep 10
/home/pi/bitcoin/src/bitcoind -daemon

Add it as a cron job on boot:

pi@raspberrypi~$ chmod +x bitcoin-start.sh
pi@raspberrypi~$ crontab -u pi -e

Add this line to the bottom:

@reboot /home/pi/bitcoin-start.sh

So now when you reboot, bitcoind will startup.

Once the blockchain is synced – WHEW – that’s a lot of steps, but hey, if it was easy everyone would be doing it.  We’re still in the early phases here.

It’s a good idea to now make your node available to the outside world. This helps improve the security of the Bitcoin network, and you’ll be rewarded with good mojo and karma to spare. Take the time to open your heart / port to the outside world.  See how analogous technology and physics is to philosophy? 🙂

Be sure to open and forward both port 8333 (Bitcoin) and port 9735 (Lightning) on your router.

Onward to lightning.

3. Lightning strikes now

The lnd Lightning implementation was developed using Golang. Learn about why Go is great!

pi@raspberrypi~$ wget https://dl.google.com/go/go1.10.linux-armv6l.tar.gz
pi@raspberrypi~$ sudo tar -C /usr/local -xzf go1.10.linux-armv6l.tar.gz

Setup go properly by editing .bashrc:

pi@raspberrypi~$ mkdir gocode
pi@raspberrypi~$ vi .bashrc

Add these lines:

export GOPATH=~/gocode
export PATH=$PATH:$GOPATH/bin

Run your .bashrc

pi@raspberrypi~$ source .bashrc

Get one more LN dependency:

pi@raspberrypi~$ go get -u github.com/golang/dep/cmd/dep

Now we’ll install LND – the reference client, the “Lightning Daemon“:

pi@raspberrypi~$ git clone https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd
pi@raspberrypi~$ cd $GOPATH/src/github.com/lightningnetwork/lnd
pi@raspberrypi:~/gocode/src/github.com/lightningnetwork/lnd$ dep ensure
pi@raspberrypi:~/gocode/src/github.com/lightningnetwork/lnd$ go install . ./cmd/...

Again, always good to run “latest-and-greatest”, so when you want to update LND, run these commands:

pi@raspberrypi~$ cd $GOPATH/src/github.com/lightningnetwork/lnd
pi@raspberrypi:~/gocode/src/github.com/lightningnetwork/lnd$ git pull && dep ensure
pi@raspberrypi:~/gocode/src/github.com/lightningnetwork/lnd$ go install . ./cmd/...

Test your LND installation:

pi@raspberrypi:~/gocode/src/github.com/lightningnetwork/lnd$ go install; go test -v -p 1 $(go list ./... | grep -v '/vendor/')

Similar to how we setup bitcoin.conf, let’s setup lnd.conf. Replace X.X.X.X below with your public IP address. This will broadcast that you have a Lightning Node to other nodes, and auto-connect to available channels:

pi@raspberrypi:~$ cd data
pi@raspberrypi:~/data$ mkdir LightningData
pi@raspberrypi:~/data$ cd LightningData
pi@raspberrypi:~/data/LightningData$ vi lnd.conf

Add these lines:

[Application Options]
debuglevel=debug
debughtlc=true
maxpendingchannels=10
noencryptwallet=1
externalip=X.X.X.X

[Bitcoin]
bitcoin.active=1
bitcoin.mainnet=1
bitcoin.node=bitcoind

[Autopilot]
autopilot.active=1
autopilot.maxchannels=10
autopilot.allocation=1.0

Add a symbolic link for ~/.lnd:

pi@raspberrypi:~/data/LightningData$ cd ~
pi@raspberrypi:~$ ln -s /home/pi/data/LightningData/ ~/.lnd

Create a bash file to start it up:

pi@raspberrypi~:~$ vi lightning-start.sh

With these lines:

#!/bin/bash
sleep 20
/home/pi/gocode/bin/lnd

OK, the Lightning Node software is installed and configured. Now it’s time to set it up to run at boot time:

pi@raspberrypi:~$ chmod +x lightning-start.sh
pi@raspberrypi:~$ crontab -u pi -e

Add this line to the bottom, under the bitcoin-start.sh line:

@reboot /home/pi/lightning-start.sh

You can reboot your Raspberry Pi now, and both bitcoind and lnd will start up. For now, let’s just start it manually:

pi@raspberrypi:~$ ./lightning-start.sh &

4. Bolt it together

At this point, both Bitcoin and Lightning are running and serving the world! There’s an incredible amount of detail for both the Bitcoin and Lightning protocols and commands, too much to cover in this post.  That said, here’s a few to get started:

Create a new wallet:

pi@raspberrypi:~$ lncli create

Get a new receiving address:

pi@raspberrypi:~$ lncli newaddress p2wkh

Send a small amount of Bitcoin to your Lightning Node. As of this post, LND is still beta! Be careful, and just send a small amount of BTC.

Run these to see some diagnostic info:

pi@raspberrypi:~$ lncli getinfo
pi@raspberrypi:~$ lncli listpeers
pi@raspberrypi:~$ lncli listchannels
pi@raspberrypi:~$ lncli listpayments

Looking back, that was quite a few steps, right? I know that this can be simplified using Docker, and I may do this at some point. This is my predecessor guide to packing this up as Docker container that as a future iteration.

You made it! There’s obviously a lot to Lightning, and this is just the beginning. These are the very early days. Soon, Lightning will live on your phone and desktop machines and you won’t even realize you’re using it. It will be as seamless as mobile location services are today. For now, plowing through these steps helps you understand how it all works, and you can sleep well knowing that your little $35 computer is helping grow and secure the network for Bitcoin – the world’s future currency.

Now that you’re up and running with a full Bitcoin Lightning Network node, what happens to it if there’s a problem? I’ll tackle maintenance, monitoring, and health in my next post!

Graphic Credit: cybrbeast http://www.reddit.com/r/Bitcoin/comments/1t6nvd/i_improved_my_tron_bitcoin_wallpaper_and_its_now/

Money plays a very substantial role in our lives – duh.  It is the fabric of almost everything we do and how we do it.  Where we live, what we drive, where we work, how we travel, what we eat, what we do in our spare time – it all revolves around money in some way.  We’re born knowing nothing about it – yet some are born into it.  It certainly isn’t something we instinctively know – yet it’s easily understood.  Every society and culture has some sort of currency as a means of exchange.  Since the beginnings of civilization, humans have invented methods to represent value via currency.  Whether it be sea shells, diamonds, gold, stocks, the number in a computer at your bank, or the paper dollars in your pocket.  Why are diamonds “worth” more than a handful of sand?  Because diamonds are more scarce.  Money means something because we as a collective society have decided it does.

I’ve been quietly studying Bitcoin for years, and today is the first day I’ve ever discussed it publicly.  Today is a milestone day in the history of Bitcoin, after the mysterious inventor of Bitcoin, Satoshi Nakamoto, was “apparently” finally found, hiding in plain sight, living just an hour away from me.  Well, maybe not.  It seems that maybe Newsweek was wrong.  Either way, today is the day I’ve decided share my thoughts.  I first discovered Bitcoin in November 2011, when I read the seminal The Rise and Fall of Bitcoin in Wired Magazine.  I was fascinated by it, but like the title implies, I thought it was dead, and that Bitcoin was over.  About 6 months later, I started seeing that Bitcoin was alive and kicking, and I began again with a renewed interest.  I studied the code, I read and re-read Nakamoto’s paper, and I immersed myself reading pretty much everything there is to read about Bitcoin.  I read books about money, the history of money, how money is physically manufactured, how inflation works, the role of the Fed, the history of the gold standard, and more.  All in an effort to wrap my head around something so complicated, yet so simple.  As some of my friends will tell you – it’s a common topic when hanging out with me – Bitcoin and of course, Tesla.  It sparked something in me that I hadn’t felt since my good friend and colleague, Paul Melmon, showed me a Web Browser (Netscape), for the first time in 1994.  I knew that Bitcoin was something incredible.

Bitcoin is quite simply, “The Internet of Money”.  As Bitcoin expert Andreas Antonopoulos has said, “Bitcoin is an invention, and it cannot be uninvented“.  Bitcoin is here and it’s here to stay.  I often get asked, “Well, what if they shut it down?”.  My answer is usually something like, by “they”, I’m assuming you’re talking about the United States Government, and yes, governments can make it difficult or illegal to transact in Bitcoin in their country’s jurisdictions, but they cannot shut it down across the globe.  No one can.  It’s out there. It’s on the Internet and it will live in some form forever and it cannot be shut down.  Last December, Bitcoin got national media attention as the exchange rate against the US dollar rose to over $1100 / 1 BTC.  I knew in that moment then that it was the end of Bitcoin’s quiet growth among techies – everyone will now hear of it.  When it hit the mainstream, I imagined all the pump-and-dump Wolves of Wall street scheming on how to best profit from it.  And profit they will.

The way I see it, as of this post, the Bitcoin market cap in USD is about $8 Billion.  That is an absolutely small number when you think about the value of all the currencies combined in the world.  It will only grow as Bitcoin becomes more popular and is adopted and accepted in more places both on-line and off-line.  Since the Internet, borders matter less and less, and the world needs a global currency.  A currency where its value is unregulated (aka un-mismanaged), anti-inflationary, and scarce.  Bitcoin is that – a currency that is built on cryptography and math and cannot be manipulated or forged.

News around Bitcoin emerges daily – some good, some bad.  Companies are being formed each week around Bitcoin and merchants are adding Bitcoin as a payment option at a fast clip.  If you have questions about Bitcoin there are numerous resources that can explain it better than me.  Here’s a few: bitcoin.org, bitcoin on reddit, bitcoin on Google, a top VCs thoughts – just look around, but look smartly.  Bitcoin is still VERY misunderstood.  Like news about Tesla, try and filter the real news, the real truth from the fear, uncertainty, and doubt the way news organizations present information.  They’re often flat-out wrong.  Validate what you hear and learn for yourself.  Find the truth.  Question everything.

I often get asked, “How do I get started?”.  I usually send people to Coinbase if they’re ready to buy Bitcoin for USD.  It’s pretty easy to sign up.  I’ve challenged a few of my friends over IM with frantic instructions to “Quick.  Go here: http://blockchain.info, paste the wallet address in the IM.  Do it in < 3 minutes I will send you some Bitcoin.  Ask no questions.  GOOOOO”.  NONE of them have failed.

To the skeptics of Bitcoin – we’ve heard you before.  You’re the same people that thought the government should “ban” or “regulate” the Internet.  You’re the same people that think Tesla Motors is a bad idea.  You’re the Telcos that wish you could ban VOIP.  We know who you are and we see through you.  We see the politician, Joe Manchin, and we question your motives and the banks behind your corruptness.  Bitcoin will succeed because it fills a need – and over time will clear the obstacles thrown at it.  Those that fear it, don’t understand it.

Bitcoin is better than the Dollar.  Bitcoin is better than your credit card and your bank account.  But Bitcoin is a baby – a very small baby.  It’s in its infancy, just like the Internet was before it exploded around 1994.  It will take a few years, but it will happen.  Bitcoin is your world currency.  It’s your open source technology.  Get used to it.  Now go get some Bitcoin!

Brett Morrison – Official Site

The official web site of Brett Morrison, Self-Made Technology Entrepreneur.

Links

No feed found with the ID 1. Go to the All Feeds page and select an ID from an existing feed.

Archives