<blockquote>
<ol>
<li>Does it work something like this?</li>
</ol>
</blockquote>
<p>No, not really.</p>
<p><code>generateblock</code> is a testing only RPC that actually mines a block using the internal CPU miner, itt does not make a block template. So it's completely irrelevant to this.</p>
<p>There are basically two ways of inserting a transaction:</p>
<ol>
<li>The miner would put the transaction in their own mempool (and possibly end up broadcasting it) by using <code>sendrawtransaction</code>. Then they would use <code>prioritisetransaction</code> to artificially set the transaction's fee so that it will appear in a block template generated by <code>getblocktemplate</code>.</li>
<li>They are using some external block template generator that will do the insertion itself. This software may begin with a block template created by <code>getblocktemplate</code>, but it will have to also implement a lot of the block assembly code itself to verify that the template it ends up producing is valid.</li>
</ol>
<blockquote>
<ol start="2">
<li>I imagine the node software is constantly updating the block to maximize the amount of fees received. Does it mean it overrides the transaction I added manually?</li>
</ol>
</blockquote>
<p>If they used method 1, no there would not be any overriding of the manual transaction since bitcoind remembers the modified fee and will continue to account for it until that transaction is confirmed.</p>
<p>For method 2, the external template software is doing the insertion so it will remember. That external software may even be (re)building the template anyways, so it's basically what bitcoind is doing in method 1.</p>
<blockquote>
<ol start="3">
<li>Is there some UI that allows you to do this? E.g. displays the current block template + transactions in mempool and allows you to replace transaction in a block template with transaction from the mempool? If not, I might attempt to build something in that fashion.</li>
</ol>
</blockquote>
<p>I don't think there are any such software that is publicly available. These days, block templates are produced by pools, and these pools often use custom software, so they may have tooling that does this. But it would not be available to the public.</p>

CC BY-SA 4.0
2024-04-20T19:14:37.283Z
Much clearer now, thank you for the explanation!
pycan
CC BY-SA 4.0
2024-04-20T18:41:13.933Z
2024-04-20T18:41:13.933Z
Ava Chow
<p>Here's my idea from the quick research:</p>
<ol>
<li><p>Miners use <a href="https://developer.bitcoin.org/reference/rpc/getblocktemplate.html" rel="nofollow noreferrer">getblocktemplate</a> RPC method.</p>
</li>
<li><p>In the obtained block template, they remove some transaction and instead place in other transaction that wouldn't normally get there (e.g. 0 fee transaction for a friend).</p>
</li>
<li><p>They use <a href="https://developer.bitcoin.org/reference/rpc/generateblock.html" rel="nofollow noreferrer">generateblock</a> RPC method and provide the updated block template.</p>
</li>
</ol>
<p>Questions:</p>
<ol>
<li><p>Does it work something like this?</p>
</li>
<li><p>I imagine the node software is constantly updating the block to maximize the amount of fees received. Does it mean it overrides the transaction I added manually?</p>
</li>
<li><p>Is there some UI that allows you to do this? E.g. displays the current block template + transactions in mempool and allows you to replace transaction in a block template with transaction from the mempool? If not, I might attempt to build something in that fashion.</p>
</li>
</ol>

<bitcoin-core><transactions><block><mempool>
How do miners manually add transaction to a block template?
pycan
# How do miners manually add transaction to a block template?

(Asked by: username_0 on 2024-04-20)

Here's my idea from the quick research:

1. Miners use [getblocktemplate](https://developer.bitcoin.org/reference/rpc/getblocktemplate.html) RPC method.
2. In the obtained block template, they remove some transaction and instead place in other transaction that wouldn't normally get there (e.g. 0 fee transaction for a friend).
3. They use [generateblock](https://developer.bitcoin.org/reference/rpc/generateblock.html) RPC method and provide the updated block template.

Questions:

1. Does it work something like this?
2. I imagine the node software is constantly updating the block to maximize the amount of fees received. Does it mean it overrides the transaction I added manually?
3. Is there some UI that allows you to do this? E.g. displays the current block template + transactions in mempool and allows you to replace transaction in a block template with transaction from the mempool? If not, I might attempt to build something in that fashion.

**Tags:** bitcoin-core, transactions, block, mempool


---

## 1 answers

### Answer by username_1 on 2024-04-20. Score: 3 | Accepted answer

> 1. Does it work something like this?

No, not really.

`generateblock` is a testing only RPC that actually mines a block using the internal CPU miner, itt does not make a block template. So it's completely irrelevant to this.

There are basically two ways of inserting a transaction:

1. The miner would put the transaction in their own mempool (and possibly end up broadcasting it) by using `sendrawtransaction`. Then they would use `prioritisetransaction` to artificially set the transaction's fee so that it will appear in a block template generated by `getblocktemplate`.
2. They are using some external block template generator that will do the insertion itself. This software may begin with a block template created by `getblocktemplate`, but it will have to also implement a lot of the block assembly code itself to verify that the template it ends up producing is valid.

> 2. I imagine the node software is constantly updating the block to maximize the amount of fees received. Does it mean it overrides the transaction I added manually?

If they used method 1, no there would not be any overriding of the manual transaction since bitcoind remembers the modified fee and will continue to account for it until that transaction is confirmed.

For method 2, the external template software is doing the insertion so it will remember. That external software may even be (re)building the template anyways, so it's basically what bitcoind is doing in method 1.

> 3. Is there some UI that allows you to do this? E.g. displays the current block template + transactions in mempool and allows you to replace transaction in a block template with transaction from the mempool? If not, I might attempt to build something in that fashion.

I don't think there are any such software that is publicly available. These days, block templates are produced by pools, and these pools often use custom software, so they may have tooling that does this. But it would not be available to the public.

> **Comments:**
> **username_0**: Much clearer now, thank you for the explanation!  

---

