<blockquote>
  <ol>
  <li>Who selects the transactions to go into this block? If not a person, where in the Core is this included</li>
  </ol>
</blockquote>

<p>Miner select them. More specifically, node software that miners run select the transactions. Most miners use Bitcoin Core or some variation of it.</p>

<blockquote>
  <ol start="2">
  <li>How do they then get bundled as a block?</li>
  <li>How do they get passed on then to the miners?</li>
  </ol>
</blockquote>

<p>When the node software selects transactions, it creates a hexadecimal string for each transaction that represents each of the fields. That hex string follows the same <a href="https://bitcoin.org/en/developer-reference#raw-transaction-format" rel="nofollow noreferrer">format used for serializing transactions</a> for sending over the network, just as the hex representation of the bytes instead of the bytes themselves. This is then packaged together with some other information into a JSON object in the <a href="https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki" rel="nofollow noreferrer">getblocktemplate</a> format and provided over a JSON-RPC interface to mining software.</p>

<p>The mining software then takes the information provided by getblocktemplate, adds their own additional information (e.g. the nonce) and constructs a <a href="https://bitcoin.org/en/developer-reference#serialized-blocks" rel="nofollow noreferrer">serialized block</a>. Serialized blocks are byte arrays containing all of the information in a block and are the same format as sent over the network. If the block is valid, the miner sends the serialized block back to the node which then sends it to the rest of the Bitcoin network.</p>

<hr>

<p>Here is a step by step example of how a miner Alice mines a block.</p>

<ol>
<li>Alice runs Bitcoin Core which constantly receives, validates, and relays transactions and other blocks.</li>
<li>Alice runs a mining software (such as cgminer) and connects here hashing machines (e.g. an Antminer S9) to that.</li>
<li>Alice also provides to her instance of cgminer the credentials to the JSON-RPC interface for her Bitcoin Core node.</li>
<li>cgminer will use getblocktemplate and send a request for a block template to Bitcoin Core.</li>
<li>Bitcoin Core receives the getblocktemplate request and chooses transactions from its pool of valid and unconfirmed transactions that it has stored in memory. The transactions are typically selected by their fee rates, highest fee rate being selected first.</li>
<li>Bitcoin Core constructs a block template using the selected transactions and adds any additional information required.</li>
<li>Bitcoin Core responds back to cgminer over the JSON-RPC interface with the completed block template.</li>
<li>cgminer receives the block template and uses it to construct a serialized block header in a form that is acceptable to the hashing hardware</li>
<li>cgminer sends whatever data it has serialized to the hashing hardware and the  hardware computes SHA256 hashes on it while incrementing some data in the data.</li>
<li>The hashing hardware (or cgminer) checks whether a hash has a valid proof of work. If it does, skip to step 14.</li>
<li>Once the hardware exhausts all possible combinations it can try using the data given and responds back to cgminer</li>
<li>cgminer, when the hashing hardware can no longer continue with its data, sends another getblocktemplate request to Bitcoin Core for a new set of transactions and block data to try.</li>
<li>Repeat steps 4 through 12 until the hashing hardware finds a hash with a valid proof of work in setp 10.</li>
<li>Once a hash with a valid proof of work has been found, cgminer takes the data that was hashed for that valid proof of work and combines it with the serialized transactions.</li>
<li>The serialized block is converted into a hexadecimal string and sent to Bitcoin Core using the submitblock RPC command.</li>
<li>Bitcoin Core takes the hexadecimal string representing the block, converts it into a byte array, checks that the block is valid, and if it is, sends the block to the nodes that it is connected to.</li>
</ol>

CC BY-SA 4.0
2018-06-08T15:45:34.630Z
+1 for extensive. you seem to know more than you should. But one more thing. How do these bundled blocks get propagated throughout the network to other miners ? how is it made sure that some of the transactions aren't part of other blocks ?
Frank L
CC BY-SA 4.0
2018-06-08T21:07:58.817Z
@FrankL The block gets propagated through the network in a peer-to-peer fashion. Eventually they will get to the miners. When a miner receives the block it will place it to the top of his chain. After that he would exclude the transactions already included to the new block when he tries to mine the next block because otherwise it would constitute a double spend and the block would be invalid (other nodes would reject it)
Mike D
CC BY-SA 4.0
2018-06-08T06:57:46.563Z
2018-06-08T06:57:46.563Z
Ava Chow
<p>The question is not about the block being included on the block chain, but 
who actually creates a block? Like what is the process here.
Can someone walk me through this? I do know that blocks are summarized in form of a block header and contain a list of transactions. </p>

<ol>
<li>Who selects the transactions to go into this block? If not a person, where in the Core is this included</li>
<li>How do they then get bundled as a block?</li>
<li>How do they get passed on then to the miners?</li>
</ol>

<blockchain><mining-theory><block><miner-configuration>
who actually amasses or builds the blocks ... and how do they get passed to miners?
Frank L
# who actually amasses or builds the blocks ... and how do they get passed to miners?

(Asked by: username_0 on 2018-06-08)

The question is not about the block being included on the block chain, but
who actually creates a block? Like what is the process here.
Can someone walk me through this? I do know that blocks are summarized in form of a block header and contain a list of transactions.

1. Who selects the transactions to go into this block? If not a person, where in the Core is this included
2. How do they then get bundled as a block?
3. How do they get passed on then to the miners?

**Tags:** blockchain, mining-theory, block, miner-configuration


---

## 1 answers

### Answer by username_1 on 2018-06-08. Score: 2

> 1. Who selects the transactions to go into this block? If not a person, where in the Core is this included

Miner select them. More specifically, node software that miners run select the transactions. Most miners use Bitcoin Core or some variation of it.

> 2. How do they then get bundled as a block?
> 3. How do they get passed on then to the miners?

When the node software selects transactions, it creates a hexadecimal string for each transaction that represents each of the fields. That hex string follows the same [format used for serializing transactions](https://bitcoin.org/en/developer-reference#raw-transaction-format) for sending over the network, just as the hex representation of the bytes instead of the bytes themselves. This is then packaged together with some other information into a JSON object in the [getblocktemplate](https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki) format and provided over a JSON-RPC interface to mining software.

The mining software then takes the information provided by getblocktemplate, adds their own additional information (e.g. the nonce) and constructs a [serialized block](https://bitcoin.org/en/developer-reference#serialized-blocks). Serialized blocks are byte arrays containing all of the information in a block and are the same format as sent over the network. If the block is valid, the miner sends the serialized block back to the node which then sends it to the rest of the Bitcoin network.

---

Here is a step by step example of how a miner Alice mines a block.

1. Alice runs Bitcoin Core which constantly receives, validates, and relays transactions and other blocks.
2. Alice runs a mining software (such as cgminer) and connects here hashing machines (e.g. an Antminer S9) to that.
3. Alice also provides to her instance of cgminer the credentials to the JSON-RPC interface for her Bitcoin Core node.
4. cgminer will use getblocktemplate and send a request for a block template to Bitcoin Core.
5. Bitcoin Core receives the getblocktemplate request and chooses transactions from its pool of valid and unconfirmed transactions that it has stored in memory. The transactions are typically selected by their fee rates, highest fee rate being selected first.
6. Bitcoin Core constructs a block template using the selected transactions and adds any additional information required.
7. Bitcoin Core responds back to cgminer over the JSON-RPC interface with the completed block template.
8. cgminer receives the block template and uses it to construct a serialized block header in a form that is acceptable to the hashing hardware
9. cgminer sends whatever data it has serialized to the hashing hardware and the hardware computes SHA256 hashes on it while incrementing some data in the data.
10. The hashing hardware (or cgminer) checks whether a hash has a valid proof of work. If it does, skip to step 14.
11. Once the hardware exhausts all possible combinations it can try using the data given and responds back to cgminer
12. cgminer, when the hashing hardware can no longer continue with its data, sends another getblocktemplate request to Bitcoin Core for a new set of transactions and block data to try.
13. Repeat steps 4 through 12 until the hashing hardware finds a hash with a valid proof of work in setp 10.
14. Once a hash with a valid proof of work has been found, cgminer takes the data that was hashed for that valid proof of work and combines it with the serialized transactions.
15. The serialized block is converted into a hexadecimal string and sent to Bitcoin Core using the submitblock RPC command.
16. Bitcoin Core takes the hexadecimal string representing the block, converts it into a byte array, checks that the block is valid, and if it is, sends the block to the nodes that it is connected to.

> **Comments:**
> **username_0**: +1 for extensive. you seem to know more than you should. But one more thing. How do these bundled blocks get propagated throughout the network to other miners ? how is it made sure that some of the transactions aren't part of other blocks ?  
> **username_2**: @username_0 The block gets propagated through the network in a peer-to-peer fashion. Eventually they will get to the miners. When a miner receives the block it will place it to the top of his chain. After that he would exclude the transactions already included to the new block when he tries to mine the next block because otherwise it would constitute a double spend and the block would be invalid (other nodes would reject it)  

---

