Mine Mainnet 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 mainnet, you can find instructions on how to do that here:
Running a Bitcoin Mainnet Full Node
To participate as a miner on mainnet, you must have access to a mainnet bitcoin node with a wallet (and the wallet's private key). One way to accomplish this is to run bitcoin locally.
First, download a bitcoin binary, or build from source (there may be some extra requirements to building, defined here).
If you want to learn more about the technical details of mining, please review the mining guide:
Tip: It is recommended to use a persistent location for the chainstate, in the steps below we're using /bitcoin
.
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
rpcallowip
value to only allow127.0.0.1
, or the stacks miner IPv4.Modify the
rpcuser
andrpcpassword
values from the defaults below.Store the following configuration somewhere on your filesystem (ex:
$HOME/bitcoin.conf
).
Start Bitcoin
Finally, start bitcoind
as follows (adjust the conf
path to where it was created in the previous step, i.e. $HOME/bitcoin.conf
):
Note: It will take a few hours for the node to synchronize with Bitcoin Mainnet.
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/debug.log
):
Running a Stacks Blockchain miner
First, download the latest tagged stacks blockchain binary, or build from source (there may be some extra requirements to building, defined here).
Tip: It is recommended to use a persistent location for the chainstate, in the steps below we're using /stacks-blockchain
.
Generate a keychain
First, a keychain needs to be generated. With this keychain, we'll purchase some BTC from a cryptocurrency exchange, 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
(Kyk49jsPGen5C1ThhyJJH4CndLk8yLESuQJVGsbbTV3FFF9CRTJG
) will then need to be imported into the bitcoin mainnet network.
Next, a bitcoin wallet is created:
Now, import your wif (bitcoin private key) inside the newly created wallet.
Note: Be sure to replace <wif from JSON above>
with the wif value in the Generate a keychain
step.
Note: The import may take a while, because a wallet rescan is triggered. After the import has completed successfully, you can check that the address is imported with getaddressinfo
.
Once imported, we need to get some BTC to that address. You should be able to transfer BTC to this address using a cryptocurrency exchange such as Coinbase, Binance, or Kraken.
Update the Stacks Blockchain Configuration File
Now, we need to configure our node to use this Bitcoin keychain. Copy the sample mainnet miner config to your local machine in a memorable location like $HOME/mainnet-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_keychain
step, modify theseed
andmining_key
values withprivatekey
Store the following configuration somewhere on your filesystem (ex:
$HOME/mainnet-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 mainnet miner with Docker.
Ensure you have Docker installed.
Generate a Keychain and Get Some Tokens
Generate a keychain:
We need to get some BTC to that address. You should be able to transfer BTC to this address using a cryptocurrency exchange such as Coinbase, Binance, or Kraken.
Update Stacks Blockchain Docker Configuration File
Use the steps outlined above to create the configuration file.
Start the Stacks Blockchain miner with Docker
Info: The ENV VARS RUST_BACKTRACE
and STACKS_LOG_DEBUG
are optional. If removed, debug logs will be disabled.
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:
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