Following my previous guide about
how to solo mine testnet bitcoins with an ASIC and cgminer I'm now presenting a guide on how to do the same but without the need of an ASIC. That means that you'll be able to mine testnet bitcoins with any computer that has a CPU and/or a GPU.
This should work on pretty much any laptop or desktop, even those with the new M1 chips from Apple. Of course the faster the CPU/GPU, the better chances you'll have to hit some blocks.
You might be wondering how is this even possible. The answer is that the difficulty in testnet3 reverts to 1 after 20 minutes have passed with no one finding a block. A difficulty of 1 is so low that any CPU or GPU is capable of hitting a block. Note that this was the difficulty of Bitcoin in the beginning(2009). More details about this can be read here:
https://bitcoin.stackexchange.com/questions/18554/how-can-i-find-the-real-difficulty-on-testnetOK, so let's make it happen. First, you need to setup Bitcoin Core in the same way as with the other guide. Here's a copy of it for simplicity:
Step 1: Install and run Bitcoin CoreWe're going to use the folder
~/bitcoin_testnet to save everything so that it's easy to remove once you're done and to keep things simple. You can of course use a different path if you want.
Inside ~/bitcoin_testnet create a folder called data:
mkdir -p ~/bitcoin_testnet/data
Download the
Bitcoin Core for your platform into ~/bitcoin_testnet/ and extract it there.
Now let's prepare the configuration file. Create a text file named
bitcoin_testnet.conf in ~/bitcoin_testnet/ and put these content in it:
testnet=1
txindex=1
server=1
[test]
rpcport=5000
rpcallowip=YOUR_MINER_IP
rpcuser=YOUR_RPC_USER
rpcpassword=YOUR_RPC_PASSWORD
rpcbind=0.0.0.0
The thing that you need to understand here is that you're setting up the Bitcoin node to run in testnet, and you're defining an RPC port(5000 in this case, can be anything), user and password, and whitelisting a specific IP to connect to your node(YOUR_MINER_IP). You'll need these details and your Bitcoin node IP later when connecting from bfgminer.
You can now start running your Bitcoin node by doing the following(make sure to change user to your actual user):
/home/user/bitcoin_testnet/bitcoin-23.0/bin/bitcoind -conf=/home/user/bitcoin_testnet/bitcoin_testnet.conf -datadir=/home/user/bitcoin_testnet/data
If you want, you can keep this running in the background with
screen:
screen -dm -S bitcoin_testnet /home/user/bitcoin_testnet/bitcoin-23.0/bin/bitcoind -conf=/home/user/bitcoin_testnet/bitcoin_testnet.conf -datadir=/home/user/bitcoin_testnet/data
You can then see what's happening with:
screen -r bitcoin_testnet
To detach the screen, simply press
Ctrl-A and then
Ctrl-D. You'll be back in the console, and the command will continue running in the background.
Step 2: Install and run bfgminerSince cgminer removed the CPU/GPU functionality a long time ago, we're going to use bfgminer. You need to compile it from source code to activate these features, so that's what we're going to do. First let's install some dependencies:
sudo apt-get install build-essential autoconf automake libtool pkg-config libcurl4-gnutls-dev libjansson-dev uthash-dev libncursesw5-dev libudev-dev libusb-1.0-0-dev libevent-dev libmicrohttpd-dev libhidapi-dev libsensors-dev
Now we're ready to get, configure, and make bfgminer with support for CPU and GPU mining. Also note that we need to update the git: sources to https: in the .gitmodules file, otherwise it won't work. I'm using sed here to do this, but you can of course do it manually if you prefer.
cd ~/bitcoin_testnet/
git clone https://github.com/luke-jr/bfgminer
cd bfgminer
sed -i 's/git:/https:/g' .gitmodules
./autogen.sh
./configure --enable-opencl --enable-cpumining
make
After it finished the build, you can now simply start mining your testnet bitcoins:
~/bitcoin_testnet/bfgminer/bfgminer -S opencl:auto -S cpu:auto -o http://YOUR_BITCOIN_CORE_IP:5000 -u YOUR_RPC_USER -p YOUR_RPC_PASSWORD --generate-to YOUR_TESTNET_BTC_ADDRESS --coinbase-sig "Whatever you want to write"
And that's it. Your computer should now be mining with the CPU and the GPU using OpenCL. Leave it overnight and you'll probably see some testnet bitcoins in your address.
Some questions you might have:Q: Can I use only the GPU?A: You can use one or the other instead of both by simply not adding it to the command (i.e. just use -S opencl:auto for GPU only or just use -S cpu:auto for CPU only).
Q: Why are there two(or more) pools in the dashboard?A: If you are running another instance of Bitcoin Core in the local machine bfgminer will try to mine there as well. If you don't want that to happen, simply add --no-local-bitcoin to the command.
Q: Can I use a Raspberry Pi?A: Actually yes, it should work with CPU mining, but extremely slow. You might get lucky though.