Home Education Bitcoin for the befuddled
By convention, the first program a programmer writes when learning a new technology is a Hello World program: It's the simplest program possible in that it just prints the message Hello World! on the screen. Essentially, it indicates to the novice that your initial code seems to be working at the outset.
However, the Bitcoin programs we need to write must perform two main tasks: receive money and send money. In this chapter, we'll focus solely on receiving money and write a program called Hello Money!. In Appendix B we'll write a Bye-Bye Money program to send money.
Bitcoin Core vs. Bitcoind
As discussed earlier, the programming techniques described in this chapter will work with either of the wallet apps, Bitcoin Core or bitcoind. The only substantive difference between the two programs is that Bitcoin Core has a graphical UI; basically, it is just bitcoind with a frontend attached to it. Because of the friendliness of the graphical UI, we'll use Bitcoin Core for
the example in this chapter. However, bitcoind is slightly less resource-intensive and can more easily run on computer servers via a terminal console. Consequently, it's best for you to use bitcoind if you actually deploy a finished program that uses the concepts in this chapter.
You'll need a few tools to ready your machine before you begin programming, so let's get them now. The instructions provided here assume a Windows development environment; skip ahead to "For Mac Hackers" on page 219 or "For Linux Folks" on page 219 if you're using either of those platforms.
You first need to download an installer for Nodejs from the nodejs.org/ website. When you run the installer for Node.js, it will also install the Node Package Manager (npm) that we'll rely on next.
Starting Bitcoin Core
If you haven't already, download Bitcoin Core from its official website at bitcoin.org/en/download.
The first time you run Bitcoin Core in server mode, it will ask you to create a file named bitcoin.conf in a specific location and add a user ID and password to this file. Follow the directions as suggested because we'll use the userid and password shortly. Then, restart Bitcoin Core.
If you already have Bitcoin Core (previously called Bitcoin-Qt) installed but are following this tutorial for the first time, then you will need to locate your previously created bitcoin.conf file. For Windows users you might want to look in C:Users<username>AppDataRoamingBitcoinitcoin.conf. For Mac users, try /Users/< username >/Library/ApplicationSupport/Bitcoin/bitcoin. conf. For Linux users, try /home/<username>/ .bicoin/bitcoin.conf.
Gotcha for Windows users: If you try to create the bitcoin.conf file with Windows
Notepad, be aware that Notepad will (oh so helpfully) tack on a .txt extension, which Windows will also (oh so helpfully) keep completely hidden from you for your own protection (a prime example of why most hackers these days try to avoid using Windows). To circumvent this problem, put quotes around the name bitcoin.conf when you enter it into the Save As dialog in Notepad.
At this point, as is usual for a Bitcoin wallet, Bitcoin Core will take several hours downloading the blockchain before it's ready for the next steps—a perfect time for an extended lunch break!
For Mac Hackers
If you're using a Mac and are comfortable using a terminal, you can run specific commands to automatically search for, download, and install the required programs.
On Mac, download homebrew, a command-line tool that will handle the entire process for you:
For Linux Folks
If you're using flavors of Debian Linux, such as Ubuntu, you'll just use the PPA feature to install the libraries:
With a working Bitcoin Core server, we're now ready to start programming.
|< Prev||CONTENTS||Next >|