i was reading document about 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
?