<blockquote>
  <p>If there is only one output address, we can guess here that the reward is the 8 bytes before the 1976,</p>
</blockquote>

<p>No, you cannot. the <code>1976</code> is the start of the output script and can/will be different depending on the output script (i.e. address) that the pool wants to use.</p>

<hr>

<p>The stratum protocol says that the hex for the coinbase transaction is <code>coinb1 + hex(extranonce2) + coinb2</code>. <code>extranonce2</code> is produced by the miner and is of a size specified by the mining pool as the <code>Extranonce2_size</code> from the response to <code>mining.subscribe</code>.</p>

<p>So you can just create bogus <code>extranonce2</code> of the correct size and concatenate the strings together as described earlier. Then put the result into a raw transaction decoder. Without the full transaction with everything (or placeholder data) in place, you cannot really properly decode the transaction reliably.</p>

CC BY-SA 4.0
2019-09-29T15:37:11.840Z
After following the steps outlined by Andrew Chow, go here: https://bitcoin.stackexchange.com/questions/42510/how-to-decode-raw-tx-hex-programmatically
SDiv
CC BY-SA 4.0
2019-09-20T03:54:12.697Z
2019-09-20T03:54:12.697Z
Ava Chow
<p>I have a mining notification from a stratum pool. I wish to write a general script to extract the value of the block reward that the pool is taking. That is, <strong>reconstruct the block template, or at least the sum of the coinbase transaction outputs / block reward, given the stratum mining.notify JSON</strong>. For example, we have the mining.notify JSON for a Digibyte sha256d block template:</p>

<pre><code>{"id":null,"method":"mining.notify","params":["8c6e","4aab33fcf4579faee35bde813ad6f66f8e1c3fed97fb5763ac6de4d02b301277","01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff210472329000048b2c825d08","0d2f6e6f64655374726174756d2f00000000020000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9cd1576270f0000001976a914f54c85705d38622a202c6f97caf7248cc4be001c88ac00000000",[],"20000202","1908ef40","5d822c8b",true]}
</code></pre>

<p>Here, the "coinb2" string is:</p>

<pre><code>0d2f6e6f64655374726174756d2f00000000020000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9**cd1576270f000000**1976a914f54c85705d38622a202c6f97caf7248cc4be001c88ac00000000
</code></pre>

<p>and this is the important part for the output transactions.</p>

<p>It turns out that in this case the reward is cd1576270f000000, written with bytes reversed, which corresponds to a base 10 integer value of 65086559693. If there is only one output address, we can guess here that the reward is the 8 bytes before the 1976, but what if there are many output addresses? </p>

<p><strong>How can we find the sum of all outputs of the coinbase transaction given the "coinb2" string in the most general case?</strong></p>

<coinbase-transaction><stratum><getblocktemplate>
reconstruct block template from stratum mining.notify
SDiv
# reconstruct block template from stratum mining.notify

(Asked by: username_0 on 2019-09-19)

I have a mining notification from a stratum pool. I wish to write a general script to extract the value of the block reward that the pool is taking. That is, **reconstruct the block template, or at least the sum of the coinbase transaction outputs / block reward, given the stratum mining.notify JSON**. For example, we have the mining.notify JSON for a Digibyte sha256d block template:

```
{"id":null,"method":"mining.notify","params":["8c6e","4aab33fcf4579faee35bde813ad6f66f8e1c3fed97fb5763ac6de4d02b301277","01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff210472329000048b2c825d08","0d2f6e6f64655374726174756d2f00000000020000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9cd1576270f0000001976a914f54c85705d38622a202c6f97caf7248cc4be001c88ac00000000",[],"20000202","1908ef40","5d822c8b",true]}

```

Here, the "coinb2" string is:

```
0d2f6e6f64655374726174756d2f00000000020000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9**cd1576270f000000**1976a914f54c85705d38622a202c6f97caf7248cc4be001c88ac00000000

```

and this is the important part for the output transactions.

It turns out that in this case the reward is cd1576270f000000, written with bytes reversed, which corresponds to a base 10 integer value of 65086559693. If there is only one output address, we can guess here that the reward is the 8 bytes before the 1976, but what if there are many output addresses?

**How can we find the sum of all outputs of the coinbase transaction given the "coinb2" string in the most general case?**

**Tags:** coinbase-transaction, stratum, getblocktemplate


---

## 1 answers

### Answer by username_1 on 2019-09-20. Score: 2 | Accepted answer

> If there is only one output address, we can guess here that the reward is the 8 bytes before the 1976,

No, you cannot. the `1976` is the start of the output script and can/will be different depending on the output script (i.e. address) that the pool wants to use.

---

The stratum protocol says that the hex for the coinbase transaction is `coinb1 + hex(extranonce2) + coinb2`. `extranonce2` is produced by the miner and is of a size specified by the mining pool as the `Extranonce2_size` from the response to `mining.subscribe`.

So you can just create bogus `extranonce2` of the correct size and concatenate the strings together as described earlier. Then put the result into a raw transaction decoder. Without the full transaction with everything (or placeholder data) in place, you cannot really properly decode the transaction reliably.

> **Comments:**
> **username_0**: After following the steps outlined by Andrew username_1, go here: https://bitcoin.stackexchange.com/questions/42510/how-to-decode-raw-tx-hex-programmatically  

---

