What is scriptpubkey for in the coinbase transaction ? (and more..)
The mined Bitcoin &quot;goes&quot; to the scriptPubKey(s) in the coinbase transaction.
Bitcoin operates on spending transaction outputs. Submitting a block does not magically cause a transaction output to appear, you need to specifically create them. This is done through the coinbase transaction (and is really the purpose of it). The only different between a coinbase transaction is that it doesn't have any real inputs. But just like with normal transactions, coinbase transactions can create any number of transaction outputs as it wants, and these just need to follow the rules for output validity.
Thus for a miner to be paid, they need to make sure that the coinbase transaction has transaction outputs that they can spend, and that the amounts for those outputs are what they want to be paid. This means that if you want to collect transaction fees, you need to set the amount to also include the transaction fees of the block, otherwise that Bitcoin will be gone forever. The rule for output amounts in a coinbase transaction is that they must not be greater than the block subsidy + transaction fees for that block.