Mine Testnet Stacks Tokens
Introduction
For more on the technical details of mining, please review the mining guide.
The following is an abridged version of the walkthrough here, written for a Linux system. If you're on Windows or MacOS, there will be some slight modifications needed (PR's welcome!).
If you're interested in mining on the Stacks testnet, you can find instructions on how to do that here:
Running a Bitcoin Node for the Stacks Testnet
The Stacks testnet does not run on the public Bitcoin testnet - it uses a Bitcoin regtest network operated by Hiro (bitcoin.regtest.hiro.so). To participate as a miner, you must have access to a bitcoin node on that network with a wallet (and the wallet's private key). One way to accomplish this is to run bitcoin locally, peered with the Hiro regtest node.
First, download a bitcoin binary, or build from source (there may be some extra requirements to building, defined here). Use Bitcoin Core 25.0 or newer - the wallet commands below are tested against every major version from 25 through 31 (latest minor of each).
Update the Bitcoin Configuration File
Next, update the bitcoin configuration:
Optional, but recommended: Use a persistent directory to store the Bitcoin chainstate, i.e.
datadir=/bitcoin.Optional, but recommended: Update the
rpcallowipvalue to only allow127.0.0.1, or the stacks miner IPv4.Modify the
rpcuserandrpcpasswordvalues from the defaults below.Store the following configuration somewhere on your filesystem (ex:
$HOME/bitcoin.conf).
server=1
regtest=1
disablewallet=0
datadir=/bitcoin
rpcuser=btcuser
rpcpassword=btcpass
rpcallowip=0.0.0.0/0
dbcache=512
banscore=1
rpcthreads=256
rpcworkqueue=256
rpctimeout=100
txindex=1
[regtest]
bind=0.0.0.0:18444
rpcbind=0.0.0.0:18443
rpcport=18443
addnode=bitcoin.regtest.hiro.so:18444Start Bitcoin
Finally, start bitcoind as follows (adjust the conf path to where it was created in the previous step, i.e. $HOME/bitcoin.conf):
While it's syncing, you can track the progress with bitcoin-cli or the logfile (will be located where the chainstate is stored, i.e. /bitcoin/regtest/debug.log):
Running a Stacks Blockchain miner
First, download the stacks-core 4.0.2 binary, or build from source (there may be some extra requirements to building, defined here).
Generate a keychain
First, a keychain needs to be generated. With this keychain, we'll get some testnet BTC from a faucet, and then use that BTC to start mining.
To create a keychain, the simplest way is to use the stacks-cli with the make_keychain command.
After this runs, you should see some JSON printed to the screen that looks like this:
Do not lose this information - we'll need to use the privateKey, btcAddress and wif fields in later steps.
The above wif (cPdTdMgww2njhnekUZmHmFNKsWAjVdCR4cfvD2Y4UQhFzMmwoW33) will then need to be imported into the bitcoin testnet network.
Next, a bitcoin wallet is created:
Required: the node never creates this wallet - it only loads the wallet named by burnchain.wallet_name and exits at startup if it does not exist. The name chosen here (miner) is the value to set for wallet_name in the node config below.
The wallet only needs to watch the miner's addresses: the stacks node signs its bitcoin transactions itself, so no private key is ever stored in bitcoind (disable_private_keys=true above). Your wif (bitcoin private key) is used once, in the getdescriptorinfo call below, to derive the watch-only descriptor.
First, convert the wif into its public descriptor:
Then import the descriptor value returned above into the miner wallet - paste it verbatim, it already ends with its #checksum. A combo(...) descriptor covers both the legacy and the segwit address of the key, so the same wallet works whether or not the miner runs with segwit = true:
The expected output is [{"success": true}] - importdescriptors reports failures inside this JSON rather than with a non-zero exit code.
After the import has completed successfully, you can check that the address is imported with getaddressinfo - ismine should be true.
Once imported, we need to get some testnet BTC to that address. The public Bitcoin testnet faucets won't work here - the Stacks testnet runs on its own regtest network, so use the Hiro testnet BTC faucet with the btcAddress from the keychain step:
Update the Stacks Blockchain Configuration File
Now, we need to configure our node to use this Bitcoin keychain. Copy the sample testnet miner config to your local machine in a memorable location like $HOME/testnet-miner-conf.toml.
Next, update the stacks configuration:
Optional, but recommended: Use a persistent directory to store the Stacks chainstate, i.e.
working_dir = "/stacks-blockchain"From the
make_keychainstep, modify theseedvalue withprivatekeyRequired: set
wallet_nameto the bitcoin wallet you created above (miner)Required: set
usernameandpasswordto match therpcuserandrpcpasswordfrom your bitcoin configurationStore the following configuration somewhere on your filesystem (ex:
$HOME/testnet-miner-conf.toml)
Start the Stacks Blockchain
To run your miner, run this in the command line:
Your node should start. It will take some time to sync, and then your miner will be running.
Enable Debug Logging
In case you are running into issues or would like to see verbose logging, you can run your node with debug logging enabled. In the command line, run:
Optional: Running a Stacks Blockchain miner with Docker
Alternatively, you can run a Stacks testnet miner with Docker.
Ensure you have Docker installed.
Generate a Keychain and Get Some Tokens
Generate a keychain:
Now, we need to get some tBTC. Grab the btcAddress field and request funds from the Hiro testnet BTC faucet:
Update Stacks Blockchain Docker Configuration File
Use the steps outlined above to create the configuration file.
Start the Stacks Blockchain miner with Docker
You can review the node logs with this command:
Optional: Running in Kubernetes with Helm
In addition, you're also able to run a Stacks miner in a Kubernetes cluster using the stacks-blockchain Helm chart.
Ensure you have the following prerequisites installed:
minikube (Only needed if standing up a local Kubernetes cluster)
Generate keychain and get some tokens
Use the steps outlined above
Install the chart and run the miner
To install the chart with the release name my-release and run the node as a miner:
The miner wallet must already exist on the bitcoind instance the chart points at (config.burnchain.peer_host and its RPC credentials).
You can review the node logs with this command:
For more information on the Helm chart and configuration options, please refer to the chart's homepage.
Last updated
Was this helpful?