Mine mainnet Stacks tokens

Set up and run a miner on the Stacks 2.0 mainnet
beginners
10 minutes

Introduction

Make sure you've followed the Running mainnet node tutorial. Once completed it's only a few more steps to run a proof-of-burn miner on the mainnet.

Graphic for: Running a mainnet node
Running a mainnet node
tutorial
Learn how to set up and run a mainnet node

If you're interested in mining on the testnet, you can find instructions on how to do that here:

Graphic for: Mine testnet Stacks tokens
Mine testnet Stacks tokens
tutorial
Set up and run a miner on the Stacks 2.0 testnet

If you want to learn more about the technical details of mining, please review the mining guide:

Graphic for: Mining
Mining
A guide to mining on Stacks 2.0

Running bitcoind locally

To participate as a miner on mainnet, you must have access to a mainnet bitcoin node. One way to accomplish this is to run bitcoind locally. Ensure your computer meets the minimum hardware requirements before continuing.

First, download the bitcoind software for your platform from https://bitcoin.org/en/download.

Next, start bitcoind with the following configuration:

server=1 rpcuser=your-bitcoind-username rpcpassword=your-bitcoind-password txindex=0 listen=1 rpcserialversion=0 maxorphantx=1 banscore=1 bind=0.0.0.0:8333 rpcbind=0.0.0.0:8332 rpcport=8332server=1rpcuser=your-bitcoind-usernamerpcpassword=your-bitcoind-passwordtxindex=0listen=1rpcserialversion=0maxorphantx=1banscore=1bind=0.0.0.0:8333rpcbind=0.0.0.0:8332rpcport=8332

Finally, start bitcoind as follows:

bitcoind -conf=path/to/bitcoin.confbitcoind -conf=path/to/bitcoin.conf

It may take a few days for the node to synchronize with the Bitcoin mainnet.

Running a miner

First, a keychain needs to be generated. With this keychain, we'll purchase some BTC from a crytpocurrency exchange, and then use that BTC to start mining.

To get a keychain, the simplest way is to use the stacks-cli. We'll use the make_keychain command.

npx @stacks/cli make_keychain 2>/dev/null | json_pp > keychain.txtnpx @stacks/cli make_keychain 2>/dev/null | json_pp > keychain.txt

After this runs, you should see some JSON in the new keychain.txt file that looks like this:

{ "mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur", "keyInfo": { "privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801", "address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF", "btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND", "index": 0 } }{ "mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur", "keyInfo": { "privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801", "address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF", "btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND", "index": 0 }}

Don't lose this information - we'll need to use the privateKey field later on.

The above BTC address will then need to be imported into the BTC network.

bitcoin-cli -rpcport=8332 -rpcuser=your-user -rpcpassword=your-password importaddress <btcAddress from JSON above>bitcoin-cli -rpcport=8332 -rpcuser=your-user -rpcpassword=your-password importaddress <btcAddress from JSON above>

Once imported, we need to get some BTC to that address. You should be able to transfer BTC to this address using a crytpocurrency exchange such as Coinbase, Binance, or Kraken.

Now, we need to configure our node to use this Bitcoin keychain. Clone the stacks-blockchain repository to your local machine if you haven't already. In the stacks-blockchain folder, modify the file at testnet/stacks-node/conf/mainnet-miner-conf.toml.

Update the following properties:

[node] ... # Enter your private key here seed = "replace-with-your-private-key" local_peer_seed = "replace-with-your-private-key" ... [burnchain] ... # To mine on mainnet, you need to run bitcoind locally # Details can be found in above section, 'Running bitcoind locally' peer_host = "127.0.0.1" username = "<USERNAME>" password = "<PASSWORD>" ...[node]...# Enter your private key hereseed = "replace-with-your-private-key"local_peer_seed = "replace-with-your-private-key"...[burnchain]...# To mine on mainnet, you need to run bitcoind locally# Details can be found in above section, 'Running bitcoind locally'peer_host = "127.0.0.1"username = "<USERNAME>"password = "<PASSWORD>"...

Now, grab your privateKey from earlier, when you ran the make_keychain command. Replace the seed field with your private key. Save and close this configuration file.

To run your miner, run this in the command line:

stacks-node start --config=./testnet/stacks-node/conf/mainnet-miner-conf.tomlstacks-node start --config=./testnet/stacks-node/conf/mainnet-miner-conf.toml

Your node should start. It will take some time to sync, and then your miner will be running.

Creating an optimized binary

The steps above are great for trying to run a node temporarily. If you want to host a node on a server somewhere, you might want to generate an optimized binary. To do so, use the same configuration as above, but run:

cd testnet/stacks-node cargo build --release --bin stacks-nodecd testnet/stacks-nodecargo build --release --bin stacks-node

The above code will compile an optimized binary. To use it, run:

cd ../.. ./target/release/stacks-node start --config=./mainnet-miner-conf.tomlcd ../.../target/release/stacks-node start --config=./mainnet-miner-conf.toml

For a full reference of subcommands and configuration options used by stacks-node, please see this page.

Graphic for: Stacks Node Configuration
Stacks Node Configuration
Configuration parameters and options for the stacks-node binary

To read more about the technical details of mining on the Stacks 2.0 network, have a look at the minig guide:

Graphic for: Mining
Mining
A guide to mining on Stacks 2.0

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:

STACKS_LOG_DEBUG=1 stacks-node mainnetSTACKS_LOG_DEBUG=1 stacks-node mainnet

Running a miner in Windows

Prerequisites

Make sure you've followed the Running the mainnet node on Windows tutorial and Running itcoind locally section above before starting this tutorial.

Generate keychain and get mainnet tokens in Windows

To setup the miner, first we need to generate a keychain. With this keychain, we'll purchase some BTC from a crytpocurrency exchange, and then use that BTC to start mining.

To get a keychain, the simplest way is to use the stacks-cli. We'll use the stx make-keychain command.

Generate a keychain:

npm install --global @stacks/cli stx make_keychain > cli_keychain.json type cli_keychain.jsonnpm install --global @stacks/clistx make_keychain > cli_keychain.jsontype cli_keychain.json

After this runs, you'll probably see some installation logs, and at the end you should see some JSON that looks like this:

{ "mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur", "keyInfo": { "privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801", "address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF", "btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND", "index": 0 } }{ "mnemonic": "exhaust spin topic distance hole december impulse gate century absent breeze ostrich armed clerk oak peace want scrap auction sniff cradle siren blur blur", "keyInfo": { "privateKey": "2033269b55026ff2eddaf06d2e56938f7fd8e9d697af8fe0f857bb5962894d5801", "address": "STTX57EGWW058FZ6WG3WS2YRBQ8HDFGBKEFBNXTF", "btcAddress": "mkRYR7KkPB1wjxNjVz3HByqAvVz8c4B6ND", "index": 0 }}

The above BTC address will then need to be imported into the BTC network.

bitcoin-cli -rpcport=8332 -rpcuser=your-user -rpcpassword=your-password importaddress <btcAddress from JSON above>bitcoin-cli -rpcport=8332 -rpcuser=your-user -rpcpassword=your-password importaddress <btcAddress from JSON above>

Once imported, we need to get some BTC to that address. You should be able to transfer BTC to this address using a crytpocurrency exchange such as Coinbase, Binance, or Kraken.

Update configuration file

Now, we need to configure our node to use this Bitcoin keychain. Clone the stacks-blockchain repository to your local machine if you haven't already. In the stacks-blockchain folder, modify the file at testnet/stacks-node/conf/mainnet-miner-conf.toml.

Update the following properties:

[node] ... # Enter your private key here seed = "replace-with-your-private-key" local_peer_seed = "replace-with-your-private-key" ... [burnchain] ... # To mine on mainnet, you need to run bitcoind locally # Details can be found in above section, 'Running bitcoind locally' peer_host = "127.0.0.1" username = "<USERNAME>" password = "<PASSWORD>" ...[node]...# Enter your private key hereseed = "replace-with-your-private-key"local_peer_seed = "replace-with-your-private-key"...[burnchain]...# To mine on mainnet, you need to run bitcoind locally# Details can be found in above section, 'Running bitcoind locally'peer_host = "127.0.0.1"username = "<USERNAME>"password = "<PASSWORD>"...

Now, grab your privateKey from earlier, when you ran the stx make_keychain command. Replace the seed field with your private key. Save and close this configuration file.

Run the miner

To start your miner, run this in the command line:

stacks-node start --config=testnet/stacks-node/conf/mainnet-miner-conf.tomlstacks-node start --config=testnet/stacks-node/conf/mainnet-miner-conf.toml

Your node should start. It will take some time to sync, and then your miner will be running.

Enable debug logging in Windows

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:

set RUST_BACKTRACE=full; set STACKS_LOG_DEBUG=1; stacks-node start --config=mainnet-miner-conf.tomlset RUST_BACKTRACE=full;set STACKS_LOG_DEBUG=1;stacks-node start --config=mainnet-miner-conf.toml

Optional: Running with Docker

Alternatively, you can run the mainnet node with Docker.

Generate keychain and get tokens

Generate a keychain:

docker run -i node:14-alpine npx @stacks/cli make_keychain 2>/dev/nulldocker run -i node:14-alpine npx @stacks/cli make_keychain 2>/dev/null

We need to get some BTC to that address. You should be able to transfer BTC to this address using a crytpocurrency exchange such as Coinbase, Binance, or Kraken.

Update configuration file

Now, we need to configure our node to use this Bitcoin keychain. Clone the stacks-blockchain repository to your local machine if you haven't already. In the stacks-blockchain folder, modify the file at testnet/stacks-node/conf/mainnet-miner-conf.toml.

Update the following properties:

[node] ... # Enter your private key here seed = "replace-with-your-private-key" local_peer_seed = "replace-with-your-private-key" ... [burnchain] ... # To mine on mainnet, you need to run bitcoind locally # Details can be found in above section, 'Running bitcoind locally' peer_host = "127.0.0.1" username = "<USERNAME>" password = "<PASSWORD>" ...[node]...# Enter your private key hereseed = "replace-with-your-private-key"local_peer_seed = "replace-with-your-private-key"...[burnchain]...# To mine on mainnet, you need to run bitcoind locally# Details can be found in above section, 'Running bitcoind locally'peer_host = "127.0.0.1"username = "<USERNAME>"password = "<PASSWORD>"...

Now, grab your privateKey from earlier, when you ran the stx make_keychain command. Replace the seed field with your private key. Save and close this configuration file.

Start the miner

docker run -d \ --name stacks_miner \ --rm \ --network host \ -e RUST_BACKTRACE="full" \ -e STACKS_LOG_DEBUG="1" \ -v "$(pwd)/testnet/stacks-node/conf/mainnet-miner-conf.toml:/src/stacks-node/mainnet-miner-conf.toml" \ -p 20443:20443 \ -p 20444:20444 \ blockstack/stacks-blockchain:latest \ /bin/stacks-node start --config /src/stacks-node/mainnet-miner-conf.tomldocker run -d \ --name stacks_miner \ --rm \ --network host \ -e RUST_BACKTRACE="full" \ -e STACKS_LOG_DEBUG="1" \ -v "$(pwd)/testnet/stacks-node/conf/mainnet-miner-conf.toml:/src/stacks-node/mainnet-miner-conf.toml" \ -p 20443:20443 \ -p 20444:20444 \ blockstack/stacks-blockchain:latest \/bin/stacks-node start --config /src/stacks-node/mainnet-miner-conf.toml

You can review the node logs with this command:

docker logs -f stacks_minerdocker logs -f stacks_miner

Optional: Running in Kubernetes with Helm

In addition, you're also able to run a mainnet node in a Kubernetes cluster using the stacks-blockchain Helm chart.

Ensure you have the following prerequisites installed on your machine:

Generate keychain and get some tokens

Generate a keychain:

docker run -i node:14-alpine npx @stacks/cli make_keychain 2>/dev/nulldocker run -i node:14-alpine npx @stacks/cli make_keychain 2>/dev/null

We need to get some BTC to that address. You should be able to transfer BTC to this address using a crytpocurrency exchange such as Coinbase, Binance, or Kraken.

Install the chart and run the miner

To install the chart with the release name my-release and run the node as a miner:

minikube start # Only run this if standing up a local Kubernetes cluster helm repo add blockstack https://charts.blockstack.xyz helm install my-release blockstack/stacks-blockchain \ --set config.node.miner=true \ --set config.node.seed="replace-with-your-privateKey-from-generate-keychain-step" \ --set config.burnchain.mode="mainnet"minikube start # Only run this if standing up a local Kubernetes clusterhelm repo add blockstack https://charts.blockstack.xyzhelm install my-release blockstack/stacks-blockchain \ --set config.node.miner=true \ --set config.node.seed="replace-with-your-privateKey-from-generate-keychain-step" \ --set config.burnchain.mode="mainnet"

You can review the node logs with this command:

kubectl logs -l app.kubernetes.io/name=stacks-blockchainkubectl logs -l app.kubernetes.io/name=stacks-blockchain

For more information on the Helm chart and configuration options, please refer to the chart's homepage.

Next
Mine testnet Stacks tokens
Powered by