Book Image

Bitcoin Essentials

By : Albert Szmigielski
Book Image

Bitcoin Essentials

By: Albert Szmigielski

Overview of this book

Blockchain is being billed as the technology of the future. Bitcoin is the first application of that technology. Mining is what makes it all possible. Exploring mining from a practical perspective will help you make informed decisions about your mining setup. Understanding what the future may hold for blockchains, and therefore for mining, will help you position yourself to take advantage of the impending changes. This practical guide starts with an introduction to Bitcoin wallets, as well as mining hardware and software. You will move on to learn about different mining techniques using the CPU, GPU, FPGA, and ultimately the ASIC as an example. After this, you will gain an insight into solo mining and pool mining, and see the differences between the two. The book will then walk you through large-scale mining and the challenges faced during such operations. Finally, you will take a look into the future to see a world where blockchain-based applications are commonplace and mining is ubiquitous.
Table of Contents (15 chapters)
Bitcoin Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Mining with Bitcoin Core


The Bitcoin Core wallet has built-in capabilities for mining; therefore, it is really easy to use the wallet to mine on your machine. The wallet will use your CPU to mine. As you might recall, mining is basically hashing of a candidate block over and over again until the result is smaller than the current difficulty threshold.

To mine with your CPU and Bitcoin Core, open up the wallet software:

  1. Now click on the Help menu and select Debug Window.

  2. Then click on the Console tab—the console will appear. Remember, to see a list of all available commands, type help and press Enter.

The command to mine with your wallet is setgenerate. The syntax of the command is as follows:

setgenerate <true|false> <number of cores to be used>

To start mining with only 1 core, type setgenerate true 1:

Fig. 2.1: Starting mining in Bitcoin Core

To make sure that your wallet is mining, you can go to your Task Manager in Windows, Activity Monitor in Mac OS, or System Monitor in Linux and see if one core is working at 100%.

Fig. 2.2: Linux' System Monitor

As you can see, one core is always working at 100% capacity. You can try running setgenerate with more than one core to verify that additional cores will be working at 100%. To stop the mining process, type in the following into the Bitcoin Core wallet console:

setgenerate false

To see additional information about the setgenerate command or any other command in the Bitcoin Core software, you can type in help followed by the command name. For example, typing in: help setgenerate will give you the following output:

Fig. 2.3: The output of running the help setgenerate command

Note

In older Bitcoin Core clients, it was possible to see how fast your wallet was mining using the gethashespersec command. Since wallet-mining is no longer popular, that command has been removed and is no longer available. It is worth noting that the gethashespersec command is still available in some alt-coins wallets.

Since alt-coins are, for the most part, forks of Bitcoin, most of the discussion here regarding the Bitcoin Core wallet also translates to alt-coin wallets. So if you are really interested in seeing the number of hashes your CPU is generating, you can do that in an alt-coin wallet if you have one installed. If you do not have one, don't worry; we will show you another way to measure your CPU's hashing performance.

Note

Definition

An alt-coin is another type of cryptocurrency that was created by copying and modifying Bitcoin's code. The most popular alt-coins are Litecoin, Dogecoin, and Namecoin. For a list of the biggest (by market capitalization) cryptocurrencies see http://coinmarketcap.com/.

Mining software

The most popular software to mine with your CPU is called CPUMiner. You can find the source code on GitHub at https://github.com/pooler/cpuminer. Precompiled binaries can be downloaded from https://sourceforge.net/projects/cpuminer/files/.

Once you have downloaded and extracted the software, the next step is to configure it. The easiest way to mine is to sign up for a mining pool, then you connect to the pool with your mining software and you're done. There are literally hundreds of mining pools. We recommend that you pick a well known pool that has been in existence for a little while. For our purpose, we will use a multipool.

Note

A multipool is a pool that mines multiple coins, that is, it is not dedicated to one type of coin. These pools calculate which coin is the most profitable to mine and automatically switch your miner to mine that coin. We registered an account on a multipool with the URL: https://www.multipool.us for demonstration purposes.

The next step on any pool is to create a worker. A worker is simply a way to identify your hardware. If you are using two computers to mine, you would create two workers. Once you have your pool account and worker info set up on the pool, you are ready to start mining.

To see all the options of CPUMiner, do the following. In a terminal window, navigate to the directory from which you extracted CPUMiner; there is a file called minerd. Run the following command ./minerd --help which will result in the following output:

Fig. 2.4: Output of the minerd --help command

Let's start mining

To connect CPUMiner to a pool, you will need the following information:

  • The URL of your pool

  • The port number of the pool server

  • Your mining pool username

  • Your worker's name

  • Your worker's password

Once you have all this information, you can run CPUMiner with the following options:

./minerd --url <poolurl:port> --userpass <USERNAME.WORKER:PASSWORD> -a<algorithm>

As a concrete example, we will connect to the multipool, as shown:

./minerd --url stratum+tcp://us-west.multipool.us:9999 -a sha256d --userpass bit.miner:x

If you have connected to your pool successfully, your screen will look similar to the following screen:

Fig. 2.5: CPUMiner working

You can see that our 4-core CPU can do about 5400 kilohashes per second (KH/s) on each core. In total, that is roughly 21000 KH/s or 21 megahashes per second (MH/s), 0.021 gigahashes per second (GH/s), or 0.000021 terahashes per second (TH/s). As you can imagine, that is a very small amount when compared to the total Bitcoin network hashing power. Currently, (at block # 391770) the network hashing power is 955,300 TH/s. Solo mining Bitcoin with a CPU will statistically take a long time before a block can be solved; however, there is a chance that you can get lucky and solve a block.