I know that on this forum a lot of questions on this topic, I have checked most of these, but can’t find the solution for my task. I am creating my own algorithm for solo mining bitcoin on Python. I wrote all necessary methods for that, including hashing the Merkle root, calculating the block header etc. But now, I am stuck for a few weeks on the coinbase transaction. I have studied the coinbase transaction page on LearnMeABitcoin.com and tried to implement all logic for it, but can’t fully understand how to make one. I want to include new rules (BIP34 – block header, BIP141 – SegWit tx) in this algorithm, but my knowledge about hashing this is not enough. 🙁
Can someone provide maybe more materials, some samples of code, or describe details about generating a coinbase transaction? Any information will be very helpful, hope on your help.
Also, I am training on Bitcoin core in regtest mode, and when I use “generatetoaddress” method (for generate blocks) this one doesn’t gen coinbase tx with BIP34 & BIP141 requirements, maybe I need set more config for this one? I found someone say about blockversion arg, is it true?
Thank you all ^^
P.S. If i miss some details about my task, fell free to ask and I provide all info which I have, of sample of code which I have (it’s not working)
UPDATE
I have greate news, I find the solution and complete this) thanks all for yout support, some later I share my code for gen coinbaseTx in python.
But left only one question, i use object for generate tx like on screen, and it have some difference with coinbase tx from generataing by Bitcoin Core using generatetoaddress only in one place, filed n in first output, and it always “00000000”, like 0 in little-endian with 4 bytes I hope. Can someone explain what it is? I use p2wpkh script for hashing address, maybe this one is type for this? When I add this value all worked fine, and I successfully gen CoinbaseTx, after build block header and full block and broadcast it to node. But just for fully understanding my code, wanna to know what this “00000000” mean) Name “n” for field was by me, just temporary name.












