Mine Stacks tokens

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

Introduction

Make sure you've followed our guide for getting a Stacks 2.0 Testnet node up and running, once completed it's only a few more steps to run a proof-of-burn miner on the testnet.

Running a miner

First, we need to generate a keychain. With this keychain, we'll get some testnet BTC from a faucet, and then use that BTC to start mining.

To get a keychain, the simplest way is to use the blockstack-cli. We'll use the make_keychain command, and pass -t to indicate that we want a testnet keychain.

npx [email protected] make_keychain -tnpx [email protected] make_keychain -t

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 }}

We need to get some testnet BTC to that address. Grab the btcAddress field, and head over to the Stacks testnet website. In the BTC faucet section, past in your btcAddress, and submit. You'll be sent 0.5 testnet BTC to that address. Don't lose this information - we'll need to use the privateKey field later on.

Now, we need to configure out node to use this Bitcoin keychain. In the stacks-blockchain folder, create a new file called testnet/stacks-node/conf/testnet-miner-conf.toml.

Paste in the following configuration:

[node] rpc_bind = "0.0.0.0:20443" p2p_bind = "0.0.0.0:20444" bootstrap_node = "048dd4f26101715853533dee005f0915375854fd5be73405f679c1917a5d4d16aaa[email protected]testnet-miner.blockstack.org:20444" # Enter your private key here! seed = "replace-with-your-private-key" miner = true [burnchain] chain = "bitcoin" mode = "krypton" peer_host = "bitcoind.blockstack.org" rpc_port = 18443 peer_port = 18444 [[mstx_balance]] address = "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6" amount = 10000000000000000 [[mstx_balance]] address = "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y" amount = 10000000000000000 [[mstx_balance]] address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR" amount = 10000000000000000 [[mstx_balance]] address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP" amount = 10000000000000000[node]rpc_bind = "0.0.0.0:20443"p2p_bind = "0.0.0.0:20444"bootstrap_node = "048dd4f26101715853533dee005f0915375854fd5be73405f679c1917a5d4d16aaa[email protected]testnet-miner.blockstack.org:20444"# Enter your private key here!seed = "replace-with-your-private-key"miner = true[burnchain]chain = "bitcoin"mode = "krypton"peer_host = "bitcoind.blockstack.org"rpc_port = 18443peer_port = 18444[[mstx_balance]]address = "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"amount = 10000000000000000[[mstx_balance]]address = "ST11NJTTKGVT6D1HY4NJRVQWMQM7TVAR091EJ8P2Y"amount = 10000000000000000[[mstx_balance]]address = "ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR"amount = 10000000000000000[[mstx_balance]]address = "STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP"amount = 10000000000000000

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/testnet-miner-conf.tomlstacks-node start --config=./testnet/stacks-node/conf/testnet-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=./testnet/conf/krypton-follower-conf.tomlcd ../.../target/release/stacks-node start --config=./testnet/conf/krypton-follower-conf.toml

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:

BLOCKSTACK_DEBUG=1 stacks-node kryptonBLOCKSTACK_DEBUG=1 stacks-node krypton