<p><em>Yes, each miner decides which transactions to select into their block templates. Blocks must have a coinbase transaction, all other transactions are optional, but blocks are limited to 4,000,000 weight units.</em></p>
<p>Let me elaborate: unconfirmed transactions are relayed on the network by the participating nodes via the p2p gossip protocol. Each node maintains their own list of unconfirmed transactions in its memory pool (mempool). Miners generally pick transactions from their mempool to assemble block templates.</p>
<p>Blocks must have a <a href="https://bitcoin.stackexchange.com/q/4571/5406">coinbase transaction</a> as the first transaction in the block, and the remaining transactions must be valid and sorted topologically. A block may not exceed 4,000,000 weight units. Other than that, miners are completely free to pick and choose the composition of their block. Blocks that only contain a coinbase transaction are allowed and referred to as <a href="/questions/tagged/empty-blocks" class="post-tag" title="show questions tagged &#39;empty-blocks&#39;" rel="tag">empty-blocks</a>.</p>
<p>It is expected that miners wish to optimize their revenue by collecting the most transaction fees possible. By default, the <a href="https://bitcoincore.org/en/doc/0.16.0/rpc/mining/getblocktemplate/" rel="nofollow noreferrer"><code>getBlockTemplate</code></a> call uses a greedy algorithm that iteratively picks the set of transactions with the highest effective feerate until the block is full.  Miners may use the <a href="https://bitcoincore.org/en/doc/0.16.0/rpc/mining/prioritisetransaction/" rel="nofollow noreferrer"><code>prioritisetransaction</code></a> rpc call to reprioritize transactions for the block template consideration. Some miners may use custom software to build their blocks.</p>
<p>In effect, block templates usually overlap almost completely across miners as nodes should see the same transactions on the network (with some slight delays due to relay). However, since each miner's block template attempts to pay the block reward to themselves via the coinbase transaction and each miner has a different payout address, every block template produced by miners will be unique and no miners will ever repeat work done by another miner.</p>
<p>Given a block template, miners search that template's combination space by injecting random data via varying nonces, extranonces, timestamps, malleating the version field, etc. Each new combination yields a unique block header which is hashed using SHA-256d. If a resulting digest meets the target, the miner has found a new block. Otherwise, they create a new block template and start over.</p>
<p>Once a new block is discovered, the block author broadcasts it to their peers. Other nodes that learn about the block append it to their blockchain, update their UTXO sets, and remove the confirmed transactions from their mempools. Since the best chain can only have one block at every height, it does not make sense for an honest miner to continue mining at the old height, therefore, they switch to mining at the new height as quickly as possible.</p>

CC BY-SA 4.0
2021-02-02T16:31:17.153Z
2021-02-03T18:09:01.960Z
2021-02-03T18:09:01.960Z
Murch
<p>The answer to all your questions is yes, except for the last one. There is more that can be varied. Nonce, extranonce, transaction order, transaction selection, maybe timestamp (within +/- an hour or so) and some other contents of the block can be varied to change the hash. The higher the difficulty, the more creative miners become.</p>

CC BY-SA 4.0
2021-02-02T13:15:04.250Z
you mean it is not as simple as such some chosen transaction plus a `nonce`?  My main focus is, different miners can choose different transactions to be in the block, and different mining pools, also, have thousands of miners in it, and each miner can have their own chosen transactions in the block?
nonopolarity
CC BY-SA 4.0
2021-02-02T13:30:13.883Z
yes, yes, no - pool allocates work to prevent duplication of effort
RedGrittyBrick
CC BY-SA 4.0
2021-02-02T10:29:34.257Z
2021-02-02T10:29:34.257Z
RedGrittyBrick
<p>It is commonly said that a new block that is hoped to be added to the existing blockchain is filled with transactions, and together with a <code>nonce</code>, go through SHA256 twice, and tries to be a small enough number (with many leading <code>0</code>'s)</p>
<p>Isn't it true that each miner or mining pool, can get different transaction to fill in?    Are these transactions coming in that &quot;are hoped to be added to this new block in about 10 minutes&quot;?  Some transaction are chosen because they offer a good fee. And it is just up to the miner or mining pool to decide which transaction go in?  So then, can the miner or mining pool put in one transaction, two transactions, 0 transactions, or any number of transactions?</p>
<p>So each miner or mining pool work off a block that are filled with different transactions plus a <code>nonce</code>?</p>

<mining-theory><transaction-selection>
Which transactions go through the SHA256 process of "trying to win the new block"?
nonopolarity
# Which transactions go through the SHA256 process of "trying to win the new block"?

(Asked by: username_0 on 2021-02-02)

It is commonly said that a new block that is hoped to be added to the existing blockchain is filled with transactions, and together with a `nonce`, go through SHA256 twice, and tries to be a small enough number (with many leading `0`'s)

Isn't it true that each miner or mining pool, can get different transaction to fill in? Are these transactions coming in that "are hoped to be added to this new block in about 10 minutes"? Some transaction are chosen because they offer a good fee. And it is just up to the miner or mining pool to decide which transaction go in? So then, can the miner or mining pool put in one transaction, two transactions, 0 transactions, or any number of transactions?

So each miner or mining pool work off a block that are filled with different transactions plus a `nonce`?

**Tags:** mining-theory, transaction-selection


---

## 2 answers

### Answer by username_1 on 2021-02-02. Score: 1

*Yes, each miner decides which transactions to select into their block templates. Blocks must have a coinbase transaction, all other transactions are optional, but blocks are limited to 4,000,000 weight units.*

Let me elaborate: unconfirmed transactions are relayed on the network by the participating nodes via the p2p gossip protocol. Each node maintains their own list of unconfirmed transactions in its memory pool (mempool). Miners generally pick transactions from their mempool to assemble block templates.

Blocks must have a [coinbase transaction](https://bitcoin.stackexchange.com/q/4571/5406) as the first transaction in the block, and the remaining transactions must be valid and sorted topologically. A block may not exceed 4,000,000 weight units. Other than that, miners are completely free to pick and choose the composition of their block. Blocks that only contain a coinbase transaction are allowed and referred to as [empty-blocks](/questions/tagged/empty-blocks "show questions tagged 'empty-blocks'").

It is expected that miners wish to optimize their revenue by collecting the most transaction fees possible. By default, the [`getBlockTemplate`](https://bitcoincore.org/en/doc/0.16.0/rpc/mining/getblocktemplate/) call uses a greedy algorithm that iteratively picks the set of transactions with the highest effective feerate until the block is full. Miners may use the [`prioritisetransaction`](https://bitcoincore.org/en/doc/0.16.0/rpc/mining/prioritisetransaction/) rpc call to reprioritize transactions for the block template consideration. Some miners may use custom software to build their blocks.

In effect, block templates usually overlap almost completely across miners as nodes should see the same transactions on the network (with some slight delays due to relay). However, since each miner's block template attempts to pay the block reward to themselves via the coinbase transaction and each miner has a different payout address, every block template produced by miners will be unique and no miners will ever repeat work done by another miner.

Given a block template, miners search that template's combination space by injecting random data via varying nonces, extranonces, timestamps, malleating the version field, etc. Each new combination yields a unique block header which is hashed using SHA-256d. If a resulting digest meets the target, the miner has found a new block. Otherwise, they create a new block template and start over.

Once a new block is discovered, the block author broadcasts it to their peers. Other nodes that learn about the block append it to their blockchain, update their UTXO sets, and remove the confirmed transactions from their mempools. Since the best chain can only have one block at every height, it does not make sense for an honest miner to continue mining at the old height, therefore, they switch to mining at the new height as quickly as possible.


---

### Answer by username_2 on 2021-02-02. Score: 0

The answer to all your questions is yes, except for the last one. There is more that can be varied. Nonce, extranonce, transaction order, transaction selection, maybe timestamp (within +/- an hour or so) and some other contents of the block can be varied to change the hash. The higher the difficulty, the more creative miners become.

> **Comments:**
> **username_0**: you mean it is not as simple as such some chosen transaction plus a `nonce`?  My main focus is, different miners can choose different transactions to be in the block, and different mining pools, also, have thousands of miners in it, and each miner can have their own chosen transactions in the block?  
> **username_2**: yes, yes, no - pool allocates work to prevent duplication of effort  

---

