<p>Miners independently create coinbase transaction for block. To create coinbase transaction this transaction should be first in block and have only 1 coinbase input. Coinbase input means that outpoint transaction is 0000000000000000000000000000000000000000000000000000000000000000 and output index is FFFFFFFF. Inputs amount fro transaction calculated like block reward amount according to block height, plus all fee amounts for all other transactions inside block. Miner able to take this total amount on outputs. Miner specify own address and amount of block block reward plus fee reward. In case the miner incorrectly calculates amounts and specify greater than expected, block will be rejected by other nodes. In case miner specify lower block will be accepted, but miner lose money. </p>

<p>Example in mainnet when miner lose all reward due to an error:</p>

<p><a href="https://bitaps.com/410995608537d591d6ce5ff2a7966fa84f891c5e2269ef85e8ecdb68d5188f9b" rel="nofollow noreferrer">https://bitaps.com/410995608537d591d6ce5ff2a7966fa84f891c5e2269ef85e8ecdb68d5188f9b</a></p>

<p><a href="https://i.sstatic.net/XUUad.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XUUad.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2018-11-07T12:15:33.163Z
hi thanks for the example block! but i am still a bit confused; does this mean a miner has to calculate block rewards and tx fees both **correctly** and **by himself**? furthermore, i saw many recent coinbase txs actually send more than 12.5 btc, does this mean a miner can collect both block reward and all tx fees in this block within a single tx? thank you
Cyker
CC BY-SA 4.0
2018-11-07T13:09:14.000Z
Yes miner should calculate all amounts (reward and fees) by himself. Calculate total reward + fees and collect in single coinbase transactions.
bitaps.com
CC BY-SA 4.0
2018-11-07T11:37:14.060Z
2018-11-07T11:37:14.060Z
bitaps.com
<p>i was reading document about <a href="https://bitcoin.org/en/blockchain-guide#transaction-data" rel="nofollow noreferrer">transaction data</a> and there seems to be two contradicting paragraphs:</p>
<blockquote>
<p>Every block must include one or more transactions. The first one of these transactions must be a coinbase transaction, also called a generation transaction, which should collect and spend the block reward (comprised of a block subsidy and any transaction fees paid by transactions included in this block).</p>
<p>Blocks are not required to include any non-coinbase transactions, but miners almost always do include additional transactions in order to collect their transaction fees.</p>
</blockquote>
<p>my questions are about coinbase transactions and transaction fees:</p>
<ul>
<li><p>is a coinbase transaction automatically added (ie: assumed by consensus) for each block, or do miners have to add it explicitly as the first transaction in each block? if so, how do they mark it as a coinbase transaction? is it enough to set no inputs and list it as the first one?</p>
</li>
<li><p>how do miners collect transaction fees? do they have to explicitly add non-coinbase transactions with their own address as output? if so, do fee-collecting transactions have the same type as other transactions, or are they special in some way?</p>
</li>
</ul>
<p>the first paragraph of cited text seems to imply transaction fees in a block can be collected through the coinbase transaction, but the second paragraph seems to imply miners need to explicitly add non-coinbase transactions to collect transaction fees; if miner <code>M</code> wants to collect fees from a transaction <code>A-&gt;B</code>, must <code>M</code> also include an additional transaction <code>A-&gt;M</code> besides <code>A-&gt;B</code>? if not, how do others know where the fees are collected, that is to say, the address of <code>M</code>?</p>

<transaction-fees><mining-reward><coinbase-transaction>
collecting block reward and transaction fees
Cyker
# collecting block reward and transaction fees

(Asked by: username_0 on 2018-11-07)

i was reading document about [transaction data](https://bitcoin.org/en/blockchain-guide#transaction-data) and there seems to be two contradicting paragraphs:

> Every block must include one or more transactions. The first one of these transactions must be a coinbase transaction, also called a generation transaction, which should collect and spend the block reward (comprised of a block subsidy and any transaction fees paid by transactions included in this block).
>
> Blocks are not required to include any non-coinbase transactions, but miners almost always do include additional transactions in order to collect their transaction fees.

my questions are about coinbase transactions and transaction fees:

* is a coinbase transaction automatically added (ie: assumed by consensus) for each block, or do miners have to add it explicitly as the first transaction in each block? if so, how do they mark it as a coinbase transaction? is it enough to set no inputs and list it as the first one?
* how do miners collect transaction fees? do they have to explicitly add non-coinbase transactions with their own address as output? if so, do fee-collecting transactions have the same type as other transactions, or are they special in some way?

the first paragraph of cited text seems to imply transaction fees in a block can be collected through the coinbase transaction, but the second paragraph seems to imply miners need to explicitly add non-coinbase transactions to collect transaction fees; if miner `M` wants to collect fees from a transaction `A->B`, must `M` also include an additional transaction `A->M` besides `A->B`? if not, how do others know where the fees are collected, that is to say, the address of `M`?

**Tags:** transaction-fees, mining-reward, coinbase-transaction


---

## 1 answers

### Answer by username_1 on 2018-11-07. Score: 3 | Accepted answer

Miners independently create coinbase transaction for block. To create coinbase transaction this transaction should be first in block and have only 1 coinbase input. Coinbase input means that outpoint transaction is 0000000000000000000000000000000000000000000000000000000000000000 and output index is FFFFFFFF. Inputs amount fro transaction calculated like block reward amount according to block height, plus all fee amounts for all other transactions inside block. Miner able to take this total amount on outputs. Miner specify own address and amount of block block reward plus fee reward. In case the miner incorrectly calculates amounts and specify greater than expected, block will be rejected by other nodes. In case miner specify lower block will be accepted, but miner lose money.

Example in mainnet when miner lose all reward due to an error:

<https://username_1/410995608537d591d6ce5ff2a7966fa84f891c5e2269ef85e8ecdb68d5188f9b>

[![enter image description here](https://i.sstatic.net/XUUad.png)](https://i.sstatic.net/XUUad.png)

> **Comments:**
> **username_0**: hi thanks for the example block! but i am still a bit confused; does this mean a miner has to calculate block rewards and tx fees both **correctly** and **by himself**? furthermore, i saw many recent coinbase txs actually send more than 12.5 btc, does this mean a miner can collect both block reward and all tx fees in this block within a single tx? thank you  
> **username_1**: Yes miner should calculate all amounts (reward and fees) by himself. Calculate total reward + fees and collect in single coinbase transactions.  

---

