how to create a valid raw Coinbase transaction for miners

2 replies 275 views
orbit100Hero Member
Posts: 423 · Reputation: 2314
#1Jan 22, 2018, 01:17 PM
How does a miner create their own Coinbase transaction and set the current block reward? Is my code in the correct format or what should I do with it? Can anyone help me fix my code? When I run this code: python coinbase.py #output Raw Coinbase transaction: 01000000010000000000000000000000000000000000000000000000000000000000000000FFFFF FFF1F03FFFFFFFF190067A397CAEFF97B4CD72E20F5445D0CAF108B01BC563A4B9F000000000120 5FA012000000000000000000 Coinbase transaction hash: c8baebf962d63c5853e166a845321be4faaf5080a19020ca9effa93910ce6282 #output Current block reward for Bitcoin: 3.125 BTC EDIT: 2nd code Raw Coinbase Transaction: 01000000010000000000000000000000000000000000000000000000000000000000000000fffff fff180340e2017465737420636f696e6261736520736372697074ffffffff01205fa01200000000 1976a91467a397caeff97b4cd72e20f5445d0caf108b01bc88ac00000000 Coinbase Transaction ID (txid): 59ee3ea8f695968beeee8f1504dd59235d7948c2ec03eb60b2754c1bcb1634dd Which code is the correct one?
6 Reply Quote Share
im_apeHero Member
Posts: 629 · Reputation: 3824
#2Jan 22, 2018, 02:22 PM
One problem I see is that your input script should be pushing the block height to the stack and anything else is extra and ignored. You are pushing the address to the stack here which is not needed. Another problem is in your output. Your only output is missing the script. This is where you should use your address (the corresponding script). Additionally since nowadays blocks contain transactions with witness, your Coinbase tx must have at least one OP_RETURN output containing the witness merkle root hash. Read more here: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#commitment-structure Another thing that is not a problem if you are just testing stuff is that you shouldn't hardcode block reward like "3.125 * 10**8". Instead you should compute it based on block height and sum of fees of the txs in the block.
1 Reply Quote Share
orbit100Hero Member
Posts: 423 · Reputation: 2314
#3Jan 22, 2018, 02:33 PM
https://mempool.space/block/0000000000000000000201fa665f016252f14dcd84877ca244a44f197830a910 only one txid to solve block 4aeda5a0f2159f448f7c23b75c62233320cbe9895af0d6f43139baea97c991b2 I know how to mine to solve blocks, but before, how to make my own txid like this 4aeda5a0f2159f448f7c23b75c62233320cbe9895af0d6f43139baea97c991b2 my_addr         ='1ASzaPvnM5BM2HE5VF1VCgkwX6yUWvJTvW' block_reward = ' '              # how to get correct block reward value block_height  = 848117  # example Any_additional_imperfection inside raw txid ?? Can you make python code for the current structure for the coinbase transaction miner? using I speak a little bit of English.
3 Reply Quote Share

Related topics