Start Solo Mining A New Altcoin With CPUminer
CPUminer is not for everyone, in fact, its not for a lot of ones. When getting involved in new Altcoins right as they launch, mining with your CPU on a laptop might be enough. Regardless, here is an examination of how to compile and run CPUminer to solo mine Altcoins. It seems that most miners that work from command line work similar to CPUminer. These instructions should translate somewhat to other miners, but may not.
Obtaining and Compiling CPUminer
CPUminer is one of the oldest mining programs for mining cryptocurrencies. The first release was published on November 24th, 2010, and 42 other releases were published since. CPUminer is still the only mining software that is open source and solely for CPU (central processor unit) mining. Along side of that stunning news, it is also not a massive headache in regards to its dependencies.
Since we want to compile CPUminer on our own, we will want to use our favorite git command in terminal. This will let us clone its Github repository to our hard drive. Simply open up a new terminal window and run the following command:
$ git clone https://github.com/pooler/cpuminer
That should clone the entire source code to the default position, which is a new folder in ~ named cpuminer.
Lets use a method I call "failing intentionally" to make sure we have all the dependencies needed to compile CPUminer. If you have been following along with the Cryptocurrency Basics series, you will already have every dependency except for one. If you haven't you may run into quite a few dependencies you are missing.
I have copied the entire output log of the configure script for CPUminer at the bottom of this article. The configure script is what checks your computer for dependencies and compatibilities. It is often the best way to find out if you are missing something or not.
That is exactly what we will be doing by the way. We simply run the normal compilation process until we are told that we are missing something. This method works fairly well on most programs you may want to encode, however, there are some exceptions. Unfortunately, CPUminer is one of those exceptions. Typically when you do this, you will get a message back from the configure script that reads something like "missing libgcc". Sometimes though, you get a syntax error or other error that is more nebulous about what exactly is missing.
CPUminer Throws an Error
As there is no better way to learn than by doing, lets go ahead and cause that error to occur. First change your active directory to the new CPUminer directory:
$ cd cpuminer
Next run the autogen.sh script:
$ ./autogen.sh
Now run the configure script:
$ ./configure
On running this, we quickly receive an error:
./configure: line 5542: syntax error near unexpected token `,'
./configure: line 5542: `LIBCURL_CHECK_CONFIG(, 7.15.2, ,'
Well that gives us almost nothing helpful if we aren't the developer. This was actually such a common issue with CPUminer that it was reported as an issue on Github. If anyone noticed, that issue started way back in 2013. The surprising thing I found about this was that the solution, which is to install one of the eleven versions of libcurl, wasn't mentioned or explained properly in the installation instructions on Github. It has only been eight years since this problem started.
Getting libcurl
The version of libcurl we need is called libcurl4-openssl-dev, the version you probably already have installed on your computer is libcurl3-gnutls, which is either pre-installed on ubuntu or a dependency of some other dependency we have installed since first compiling Litecoin. Anyway around it, you just need to tell your computer to grab this new libcurl and we can be in mining town real soon.
$ sudo apt install libcurl4-openssl-dev
Less than a minute later (depending on your internet speed) and we now meet the requirements for installing CPUminer. However, we will have to backtrack a step and again run autogen.sh to get things back in order for compiling.
Compile CPUminer
$ ./autogen.sh
$ ./configure
$ sudo make
$ sudo make install
This time when configure runs it should make it all the way through. Unlike the configuration scripts we have seen before compiling altcoins, this one ends by issuing six statements from config.status about files that it is creating. The very last one is config.status: executing depfiles commands. This of course means nothing to any end user, but what it really means is that the configure script is done and we can finish things out with sudo make and sudo make install.
Once sudo make install finishes, there should be a new binary in your /usr/local/bin folder named minerd. That is your compiled mining binary, now we just need to configure it.
Configuring CPUminer
In my article about Altcoin daemons and CLI (command line interface) we needed to make a .conf file for the daemon. While you don't absolutely have to make a configuration file for CPUminer, you really should. Whenever you launch the program you will need to know quite a few different things, and these will vary based on what coin you are mining. These include things like if you are solo or pool mining, what address you are sending the mined currency to, and other variables. As always, if you are using any address for an Altcoin, you should copy and paste it and double check it.
Configuration files for CPUminer are a bit different than ones for our Altcoin daemons. That configuration file was a .conf format, which required very little formatting to be read properly by the application. Configuration files for CPUminer are in .json format, or Javascript Object Notification format. JSON is a simple method of passing along commands or parameters through SSH (Secure Shell) which is how CPUminer talks to the Altcoin daemon (and how most computers talk to each other on the same network).
Despite having the ominous "Javascript" in its name, JSON is not that difficult to figure out. JSON files all have some basic elements:
Opening and Closing Braces { }
All JSON files open with a "{" and then end with a "}". The application reads these at the start and end of the file. Don't put any additional data before or after the braces.
Modifiers and Values
JSON has its own format of encoding modifiers. An example would be how we tell CPUminer what URL to look for the mining server at:
"url" : "http://127.0.0.1:9332/"
The information is formatted as "modifier" then a full colon ":" and then "modifier value". Every line of the JSON file will end with a comma (,) except for the final line, which will not have any lines of information after it.
Modifiers when talking to CPUminer through the JSON configuration file consist of any long format command line argument. We can find all of these long format arguments by entering the following command into terminal:
$ minerd --help
This will give us an extensive list of what we can put into the JSON file (although we may not want to include all of these things). You can see the entire output below.
Usage: minerd [OPTIONS]
Options:
-a, --algo=ALGO specify the algorithm to use
scrypt scrypt(1024, 1, 1) (default)
scrypt:N scrypt(N, 1, 1)
sha256d SHA-256d
-o, --url=URL URL of mining server
-O, --userpass=U:P username:password pair for mining server
-u, --user=USERNAME username for mining server
-p, --pass=PASSWORD password for mining server
--cert=FILE certificate for mining server using SSL
-x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy
-t, --threads=N number of miner threads (default: number of processors)
-r, --retries=N number of times to retry if a network call fails
(default: retry indefinitely)
-R, --retry-pause=N time to pause between retries, in seconds (default: 30)
-T, --timeout=N timeout for long polling, in seconds (default: none)
-s, --scantime=N upper bound on time spent scanning current work when
long polling is unavailable, in seconds (default: 5)
--coinbase-addr=ADDR payout address for solo mining
--coinbase-sig=TEXT data to insert in the coinbase when possible
--no-longpoll disable long polling support
--no-getwork disable getwork support
--no-gbt disable getblocktemplate support
--no-stratum disable X-Stratum support
--no-redirect ignore requests to change the URL of the mining server
-q, --quiet disable per-thread hashmeter output
-D, --debug enable debug output
-P, --protocol-dump verbose dump of protocol-level activities
-S, --syslog use system log for output messages
-B, --background run the miner in the background
--benchmark run in offline benchmark mode
-c, --config=FILE load a JSON-format configuration file
-V, --version display version information and exit
-h, --help display this help text and exit
We will want to include some of the most basic elements for simple jobs, and then if you want to experiment with more advanced features, feel free to experiment with more advanced options. The modifiers we will use will be: url, userpass, coinbase-addr, debug, no-longpoll, no-getwork, and no-stratum.
The last three are important to configure based upon where you will be mining. If you are solo mining on a daemon running on your computer, you will want a different setting than if you are mining on a mining pool. Debug is important as it explains very clearly what is happening with the miner if something is going wrong.
Sample Configuration File
As the descriptions of all of these are above, I have put an example mining .json configuration file below.
{
"url" : "http://127.0.0.1:9332/",
"userpass" : "USERNAME:PASSWORD",
"coinbase-addr" : "ADDRESS TO MINE COINS TO",
"debug" : true,
"no-longpoll" : true,
"no-getwork" : true,
"no-stratum" : true
}
As you can see, it really is only those six modifiers that we will need to perform mining successfully. Now, lets talk about configuring the no-longpoll, no-getwork, and no-stratum modifiers. First and foremost, we have to remember these are negative modifiers, meaning that inputting true as the value will mean no, and false as the value will mean yes. With that said, don't enable these unless mining on a mining pool. If you plan on solo mining, you need to disable all of them. Otherwise you will end up either not getting any luck with mining, or your miner just wont work.
Maintaining the comma structure is crucial to the format of JSON files. However, you can add line breaks and it won't disrupt things. This can allow us to format our configuration files in a more readable way, which can help when editing it later on for different mining configurations.
Copy over the sample .json configuration file above to Sublime Text and give it any edits it needs to work and then hit save. Now, it doesn't matter really where you save it, it only matters that you remember where you saved it at and what you named it. If you haven't already figured it out, the only reason we need to go to /usr/local/bin after we compile a program is that we need to know what the name of the binary is. Once we know that, we can simply type the name of that binary from any active directory and it will work. So even if your terminal is aimed at ~/Desktop as its active directory, you can still type in minerd and launch CPUminer.
All you need to do is point your terminal window at the directory where you saved your configuration file, and then enter the following command:
$ minerd -c CONFIGFILENAME.json
Executing the above command should launch CPUminer with the information provided in the .json file you just created and you will start to see the different mining threads kicking out hash's on your terminal window.
One final note to make about CPUminer and other miners, is that there is also the "coinbase-sig" modifier. This isn't really going to mean much to most people, but if you have multiple miners (computers or instances of CPUminer) paying out to the same address mining in a pool, you will need to give each one a unique value for coinbase-sig.
Output of CPUminer ./configure Script
checking build system type...
checking host system type...
checking target system type...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for gcc option to accept ISO C99... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking whether gcc needs -traditional... no
checking dependency style of gcc... gcc3
checking for ranlib... ranlib
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sys/endian.h usability... no
checking sys/endian.h presence... no
checking for sys/endian.h... no
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for sys/sysctl.h... yes
checking whether be32dec is declared... no
checking whether le32dec is declared... no
checking whether be32enc is declared... no
checking whether le32enc is declared... no
checking for size_t... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for getopt_long... yes
checking whether we can compile AVX code... yes
checking whether we can compile XOP code... yes
checking whether we can compile AVX2 code... yes
checking for json_loads in -ljansson... no
checking for pthread_create in -lpthread... yes
checking for gawk... (cached) mawk
checking for curl-config... /usr/bin/curl-config
checking for the version of libcurl... 7.68.0
checking for libcurl >= version 7.15.2... yes
checking whether libcurl is usable... yes
checking for curl_free... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating compat/Makefile
config.status: creating compat/jansson/Makefile
config.status: creating cpuminer-config.h
config.status: cpuminer-config.h is unchanged
config.status: executing depfiles commands