What is Stacks?
Stacks is a Layer 1 blockchain and decentralized network that enables Web3, DeFi, NFTs, apps, and smart contracts on top of Bitcoin. Anything developed onchain on the Stacks platform is natively integrated with the security, stability, and economic power of Bitcoin.
Stacks enables what Ethereum and other layer 1 networks attempt, but on top of the most secure foundational layer of trust in human history: Bitcoin.
Useful resources to understand the details of Stacks, what it is, and why it is important:
What is Proof of Transfer? (PoX)
Stacks implements a new consensus mechanism called Proof of Transfer ("PoX"). PoX is a consensus algorithm between two blockchains that is conceptually equivalent to Proof of Work (PoW), and is a modification of Proof of Burn (PoB). Like PoW, PoX requires all miners to spend an existing resource of known value in order to get the chance to compete in leader election/sortition and mint the next Stacks block. And like PoW, miners are the key actors who process transactions and ultimately secure the network. Like PoB, PoX uses an established blockchain (in this case Bitcoin) to secure a new blockchain (Stacks).
PoX connects to Bitcoin with a 1:1 block ratio, meaning anything that happens on the Stacks blockchain can be verified on the Bitcoin Blockchain. Instead of burning electricity on PoW, PoX reuses already minted Bitcoins as "proof of computation" and miners represent their cost of mining in bitcoins directly. Put another way, PoX requires miners to spend bitcoin to compete rather than electricity.
A novel feature of PoX is that the bitcoin spent by miners is not destroyed, but rather transferred to STX token holders who have locked their tokens. This is known as “Stacking”. Stacking should not be confused with “Staking”, which serves a fundamentally different purpose in network security for other layer 1 networks.
Useful resources to go deeper into the details of PoX:
How does STX mining work?
STX mining is an open membership way to participate in PoX, and is responsible for confirming STX transactions and securing the Stacks network. In order for mining to be both (1) open membership and (2) honest, miners must spend a resource of known value in order to compete. With PoW, this resource is electricity, while with PoX this resource is Bitcoin itself.
To mine Stacks blocks, STX miners spend some amount of Bitcoin every block. When a miner wins a block they receive STX tokens as a reward. The more Bitcoin a miner spends per block, the higher their probability of winning that block.
For a full run through of how STX mining works, please see the documentation here.
What is the difference between STX mining & Stacking?
There are two different ways to participate in PoX consensus: STX Mining & Stacking.
STX Mining is more technically and resource intensive, and is responsible for securing the Stacks network. STX Miners spend Bitcoin every Stacks Block in order to compete to append the next block to the Stacks chain and earn the STX block reward. The Bitcoin spent by STX Miners every block is forwarded by the protocol to STX token holders who are Stacking.
Stacking is when STX token holders lock up, or “stake”, their STX tokens in order to earn the Bitcoin spent by STX Miners. In addition to locking up tokens, Stackers also signal support for the longest Stacks chain tip. In the case of contentious forks of the network, this provides an extra incentive for STX Miners to be honest. While Stacking can aid in network security as a result, it does not secure PoX.
Useful resources to understand the details of Stacking:
How can I start mining STX?
You first must setup and start running both a Bitcoin Node and a Stacks Node. You will also need to setup a Bitcoin wallet and Stacks wallet. The Bitcoin wallet will need to be funded with BTC that will be used to compete for Stacks blocks, while the Stacks wallet will collect the STX mining rewards earned whenever you win a block.
Useful links to get started:
How to setup and run a mainnet Stacks Node?
Follow this guide here.
Do I need to setup and run a Bitcoin Node in order to mine STX?
Yes. In order to mine STX you must be running a Bitcoin node. The reason is that the Stacks node needs to check 'istunspent utxos https://developer.bitcoin.org/reference/rpc/listunspent.html' for you miner via Bitcoin RPC.
What's the easiest way to set all of this up and start mining STX?
Unless you prefer to run both Bitcoin and Stacks nodes locally, we recommend spinning both up on cloud based servers. This will allow you to keep your miner running constantly much more easily.
Here is a guide for spinning up a Stacks and Bitcoin node on a cloud server, including recommended server configuration.
How can I test if my miner is working properly?
First test if your Bitcoin node is working properly by using RPC 'getblockchaininfo https://developer.bitcoin.org/reference/rpc/getblockchaininfo.html'. This will allow you to check the progress of your node syncing to the Bitcoin network. Once the node catches up latest Bitcoin block, it is running properly.
Then test your Stacks Node. After starting it, use 'syncing burn_header log' to make the Stacks node fetch data from your Bitcoin node. Once the burnchain information is fully synced, your Stacks node will send a register-key transaction and commit-block transactions. These will create Bitcoin transactions for the purpose of mining STX, which can be tracked using any Bitcoin explorer like btc.com.
If you see your address listed on Onstacks.com as competing for recent blocks, then you are mining properly.
Why do I need to spend Bitcoin to mine STX? Do I get the Bitcoin back if I don't win the next block?
The Stacks network uses an "open membership" consensus mechanism, which is PoX. Open membership means that anyone has the ability to compete to mine on the network vs. federated or trusted membership, where miners must be known by the network beforehand. In order for PoX to be and remain an open membership consensus mechanism, miners must be made to spend a resource in order to compete, and must not get that resource back. Conceptually, this is the same reason PoW and Bitcoin mining require spending electricty to compete.
As with spending electricity to mine Bitcoin, STX miners to not receive the Bitcoin they spent back if they don't win a block.
How much Bitcoin should I spend each block?
This depends on a number of mining specific factors, and is arguably the most important input when it comes to STX mining strategy. At a high level, the more Bitcoin a miner spends, the higher their chances of winning the next Stacks block. This is because leader election is conducted by combining the amount of BTC spent by each miner with an on chain verifiable random function (VRF). You can think of the VRF as an on chain a random number generator.
Therefore, while spending the most BTC will give you the highest chance of winning blocks, it will also make you spend your BTC the quickest. Spending the least amount of BTC will make your reserves last longer, but it may also make it too improbable that you will win a block. STX mining, therefore, is a numbers game. The sweet spot is somewhere in between these two values: you must have enough BTC in reserve to be able compete to mine STX long enough to see a positive return.
Onstacks can be a helpful platform to determine how much BTC to spend, as you can see the amount of BTC each miner is spending to compete live.
What is my probability of winning any given Stacks block?
The exact weight for a miner's probability to win the next Stacks block can be calculated with the following algorithm: min(median_burn_from_last_6_blocks, last_burn).
This means that my probability of winning the next block is not simply the weight of my spend compared to every other miner for a given block, but rather the median of my spend over the last 6 blocks.
This has an important consequence to note: the probability for a miner to win any of the first 3-4 blocks it competes for is functionally 0. This is because for the weighted probability to become competitive, the miner needs to build up at least 2-3 blocks of spending history before the probability weight exceeds 0.
What is the expected return from mining STX?
Miners receive both coinbase and transaction fee rewards for blocks they win.
The coinbase reward amounts are:
These "halvings" are synchronized with Bitcoin halvings.
Miners also receive Stacks fees for transactions mined in any block they produce. The amount of transaction fees per block is variable, and dependent on the specific Stacks transactions included in any given block.
For transactions mined in microblocks, the miner that produces the microblock receives 40% of the fees, while the miner that confirms the microblock receives 60% of the fees.
How do I change the amount of Bitcoin I am spending per block?
We do not recommend turning your miner off in order to change the amount of Bitcoin you are spending per Stacks block. Doing so will reset your weighted average spend back to 0 (per the algorithm min(median_burn_from_last_6_blocks, last_burn), and you will incur a 3-4 block penalty upon restart before having any reasonable probability of winning a block.
Instead, we recommend using Bitcoin's Replace-by-Fee to change the amount of BTC being spent per block on the fly, without ever stopping your miner. To read more about using this strategy, please see the Replace-by-Fee wiki.
What are Microblocks? How do I mine them?
The Stacks blockchain allows for increased transaction throughput using a mechanism called microblocks. Bitcoin and Stacks progress in lockstep, and their blocks are confirmed simultaneously. On Stacks, this is referred to as an ‘anchor block’. An entire block of Stacks transactions corresponds to a single Bitcoin transaction. This significantly improves cost/byte ratio for processing Stacks transactions. Because of simultaneous block production, Bitcoin acts as a rate-limiter for creating Stacks blocks, thereby preventing denial-of-service attacks on its peer network.
However, in between Stacks anchor blocks settling on the Bitcoin blockchain, there are also a varying number of microblocks that allow rapid settlement of Stacks transactions with a high degree of confidence. This allows Stacks transaction throughput to scale independently of Bitcoin, while still periodically establishing finality with the Bitcoin chain. The Stacks blockchain adopts a block streaming model whereby each leader can adaptively select and package transactions into their block as they arrive in the mempool. Therefore when an anchor block is confirmed, all of the transactions in the parent microblock stream are packaged and processed. This is an unprecedented method for achieving scalability without creating a totally separate protocol from Bitcoin.
As long as you are running the most up to date Stacks node version, support for Microblocks will be enabled by default. There is nothing further you need to do in order to compete to mine Microblocks.