I'm about to mine and I reached a part when I want to generate the coinbase transaction. I won't complicate things by putting in the new block transactions and getting the fees for them. All that matters is to mine a block (seems that the coinbase transaction is counted as 1 transaction for the whole block? True?)
Take a look at this PHP function and check the comments (let me know if I'm wrong somewhere)
function coinbase_gen($block_height){ //(decimal)$block_height would be the last official block number +1
$ver='01000000'; // seems that this version won't change anytime soon?
$i_count='01'; // In that situation it is always 01?
$txid='0000000000000000000000000000000000000000000000000000000000000000'; //always as well
$vout='ffffffff'; // always?
$coin_nextbytes=dechex(strlen($block_height)/2);
$block_height=SwapEndianess(dechex($block_height)); //reassign the height to VarInt
$sig=$coin_nextbytes.$block_height."f48616f4254432f53756e204368756e2059753a205a6875616e67205975616e2c2077696c6c20796f75206d61727279206d653f2f06fcc9cacc19c5f278560300";
$sig_size=dechex(strlen($sig)/2);
$sequence='ffffffff'; // Some people put 0000000 in here.. Why?
$o_count='01';
$o_value='40be402500000000'; //6.25 BTC !!!
$pubkeysize='19';
$script_pubkey='76a914bfd3ebb5485b49a6cf1657824623ead693b5a45888ac'; //Please answer..
$locktime='00000000'; // Seems good
return $ver.$i_count.$txid.$vout.$sig_size.$sig.$sequence.$o_count.$o_value.$pubkeysize.$script_pubkey.$locktime;
}
coinbase_gen((int)$last_blockn); // just example how I'll generate it.
As you can see I have many questions in the code, but I need to know about that $script_pubkey. Some blog posted it as example to mine,but I feel that any bitcoin mined will reward $script_pubkey which is somebodies wallet public key (encrypted) ? OR this does not matter for the coinbase transaction and when I submit the block with bitcoind RPC it will make sure that it will go to my wallet? This is important to know. Thanks.