user127251: Still trying to write a function to properly create a coinbase transaction and the only thing I can't seem to get a hold on is..... How to get the block height provided by getblocktemplate into the coinbase transaction?  - which I create using the createrawtransaction rpc command. But the thing is, by calling the createrawtransaction and doing
[{"txid":"0000000000000000000000000000000000000000000000000000000000000000","vout":2147483647}]{" insert address ":6.25000000}

, I'd get a processed hash which is to be added as transaction 0 within the list of transactions before building the merklehash.
This is great but this wouldn't be a valid coinbase transaction as the block height is missing!! - Which is needed as the first 8 bytes of the scriptsig within the coinbase transaction.
So it got me thinking, What if the data field  after the address field is where I insert the blocks height?
While reading the Official Bitcoin Developer RPC API Reference, I came across a parameter within the createrawtransaction rpc command -- The key must be "data", the value is hex-encoded data and I thought maybe this is where I ought to fill in the height data .... which I would grab from here and maybe somehow parse it with this ; after which I then take the hexadecimal hash and insert it within the data field.

user208: The requirement of encoding the block height in the coinbase transaction is specified in BIP34. You may want to read the actual documentation there.
Specifically, it requires the scriptSig of the coinbase's (only) transaction input to start with a push of the height, encoded as a little-endian number. For current mainnet blocks (with height above 65535), the first 4 bytes of the scriptSig have to be [0x03, height % 256, (height >> 8) % 256, height >> 16].
It is not done as an additional output (as a data output would imply), and is not possible directly using createrawtransaction, which is aimed towards general-purpose transactions, not coinbases. Coinbases are generally constructed by mining software.

127251: <p>Still trying to write a function to properly create a coinbase transaction and the only thing I can't seem to get a hold on is..... How to get the block height provided by <strong><code>getblocktemplate</code></strong> into the coinbase transaction?  - which I create using the <strong><code>createrawtransaction</code></strong> rpc command. But the thing is, <strong>by calling the <strong><code>createrawtransaction</code></strong> and doing</strong></p>
<pre><code>[{&quot;txid&quot;:&quot;0000000000000000000000000000000000000000000000000000000000000000&quot;,&quot;vout&quot;:2147483647}]{&quot; insert address &quot;:6.25000000}
</code></pre>
<p><strong>, I'd get a processed hash which is to be added as <strong>transaction 0</strong> within the list of transactions before building the merklehash.</strong></p>
<p>This is great but this wouldn't be a valid coinbase transaction as the block height is missing!! - Which is needed as the first 8 bytes of the scriptsig within the coinbase transaction.</p>
<p>So it got me thinking, What if the <strong><a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data" rel="nofollow noreferrer">data field</a></strong>  after the address field is where I insert the blocks height?</p>
<p>While reading the Official <strong><a href="https://developer.bitcoin.org/index.html" rel="nofollow noreferrer">Bitcoin Developer RPC API Reference</a></strong>, I came across a parameter within the <strong><code>createrawtransaction</code></strong> rpc command -- <strong><a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data" rel="nofollow noreferrer">The key must be &quot;data&quot;, the value is hex-encoded data</a></strong> and I thought maybe this is where I ought to fill in the height data .... which I would grab from <strong><a href="https://developer.bitcoin.org/reference/rpc/getblocktemplate.html#:%7E:text=%22height%22%20%3A%20n%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(numeric)%20The%20height%20of%20the%20next%20block" rel="nofollow noreferrer">here</a></strong> and maybe somehow parse it with <strong><a href="https://developer.bitcoin.org/reference/rpc/getblocktemplate.html#:%7E:text=%22coinbaseaux%22%20%3A%20%7B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(json%20object)%20data%20that%20should%20be%20included%20in%20the%20coinbase%27s%20scriptSig%20content" rel="nofollow noreferrer">this</a></strong> ; after which I then take the hexadecimal hash and insert it within the <strong><a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data" rel="nofollow noreferrer">data field</a></strong>.</p>
 208: <p>The requirement of encoding the block height in the coinbase transaction is specified in <a href="https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki" rel="nofollow noreferrer">BIP34</a>. You may want to read the actual documentation there.</p>
<p>Specifically, it requires the scriptSig of the coinbase's (only) transaction input to start with a push of the height, encoded as a little-endian number. For current mainnet blocks (with height above 65535), the first 4 bytes of the scriptSig have to be [0x03, height % 256, (height &gt;&gt; 8) % 256, height &gt;&gt; 16].</p>
<p>It is not done as an additional output (as a data output would imply), and is not possible directly using <code>createrawtransaction</code>, which is aimed towards general-purpose transactions, not coinbases. Coinbases are generally constructed by mining software.</p>
