<p>It is resolved.</p>

<pre><code>block_array: List = list()
block_array.append(struct.pack('&lt;L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("&lt;L", block['height']))  # 632295
block_array.append(bytes.fromhex(block['reserved']))  # 0
block_array.append(struct.pack("&lt;L", block['timestamp']))
block_array.append(struct.pack("&lt;L", block['bits']))
block_array.append(bytes.fromhex(block['nonce'])[::-1])
block_array.append(bytes.fromhex(block['solution'])[::-1])

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)
</code></pre>

<p>Fun</p>

<pre><code>def double_sha256(bytes_str: bytes):
    result = sha256(sha256(bytes_str).digest()).digest()
    return result[::-1]  # little endian
</code></pre>

CC BY-SA 4.0
2020-05-04T16:39:19.273Z
2020-05-05T06:55:28.423Z
2020-05-05T06:55:28.423Z
Джон Смит
<p>I am trying to calculate block hash # 632295</p>

<pre><code>{ 
'version': 536870912,  
'prev_block_hash': '000000017590609fd72cadc5fd05732cfa1760bd882213afbb7b788c42e115c8', 
'merkle_root': '20e8e04b62d9cd21dbcee23e445fda60a07bc5785a0a2b0b419227c6a2ec936a',  
'reserved': '00000000000000000000000000000000000000000000000000000000',  
'timestamp': 1588602316,  
'bits': 486818083,  
'nonce': '0085c0dd0000000000000000000000000000000000000000000000000106002e',  
'solution': '441cf79198cc4b0fb4dd5f9fa7be645adc4197ff655b555d4139051c9d7b82419f4824f055a5c993390569681ac67061ce041776751d6d72129c18e446dd31d4cc1e78e5d7b4ba440b1d188caffe6da433f73d9d53cfefc36505da3b9270521650a6930064', 
'height': 632295 
}
</code></pre>

<p>This is what my code for calculating the hash for Bitcoin looks like, but it does not work for BitcoinGold.</p>

<pre><code>block_array: List = list()
block_array.append(struct.pack('&lt;L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("&lt;L", block['timestamp']))
block_array.append(struct.pack("&lt;L", block['bits']))
block_array.append(struct.pack("&lt;L", block['nonce']))

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)
</code></pre>

<p>Next, I turned to the documentation:
<a href="https://github.com/BTCGPU/BTCGPU/wiki/Technical-Spec" rel="nofollow noreferrer">https://github.com/BTCGPU/BTCGPU/wiki/Technical-Spec</a></p>

<p>This suggests that I need to add 3 more fields:</p>

<blockquote>
  <p>nHeight, nReserved,nSolution</p>
</blockquote>

<p>I believe that the code should look like this for bitcoingold:</p>

<pre><code>block_array: List = list()
block_array.append(struct.pack('&lt;L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("&lt;L", block['height']))  # 632295
block_array.append(struct.pack("&lt;L", block['reversed']))  # 0
block_array.append(struct.pack("&lt;L", block['timestamp']))
block_array.append(struct.pack("&lt;L", block['bits']))
block_array.append(struct.pack("&lt;L", block['nonce'])))
block_array.append(struct.pack("B", block['solution']))

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)
</code></pre>

<p>But this does not work, because <a href="https://www.reddit.com/r/BitcoinGoldHQ/comments/b3h34h/why_isnt_the_btg_nonce_numeric/?sort=top" rel="nofollow noreferrer">nonce is not int.</a></p>

<p>As a result of executing the code, should get this hash:
<a href="https://btgexplorer.com/block/00000003dd91f04483e990a1ecc5176abdfb18f40ae2ca6b0d203127bc150998" rel="nofollow noreferrer">00000003dd91f04483e990a1ecc5176abdfb18f40ae2ca6b0d203127bc150998</a></p>

<p>How to convert "nonce" and "solution"?</p>

CC BY-SA 4.0
2020-05-07T05:14:55.657Z
Where can I ask questions about BitcoinGold?
https://bitcoin.meta.stackexchange.com/questions/1041/where-can-i-ask-questions-related-to-bitcoingold
Джон Смит
<python><block-header><bitcoin-gold>
Calculate BitcoinGold Block Header Hash
Джон Смит
# Calculate BitcoinGold Block Header Hash

(Asked by: username_0 on 2020-05-04)

I am trying to calculate block hash # 632295

```
{ 
'version': 536870912,  
'prev_block_hash': '000000017590609fd72cadc5fd05732cfa1760bd882213afbb7b788c42e115c8', 
'merkle_root': '20e8e04b62d9cd21dbcee23e445fda60a07bc5785a0a2b0b419227c6a2ec936a',  
'reserved': '00000000000000000000000000000000000000000000000000000000',  
'timestamp': 1588602316,  
'bits': 486818083,  
'nonce': '0085c0dd0000000000000000000000000000000000000000000000000106002e',  
'solution': '441cf79198cc4b0fb4dd5f9fa7be645adc4197ff655b555d4139051c9d7b82419f4824f055a5c993390569681ac67061ce041776751d6d72129c18e446dd31d4cc1e78e5d7b4ba440b1d188caffe6da433f73d9d53cfefc36505da3b9270521650a6930064', 
'height': 632295 
}

```

This is what my code for calculating the hash for Bitcoin looks like, but it does not work for BitcoinGold.

```
block_array: List = list()
block_array.append(struct.pack('<L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("<L", block['timestamp']))
block_array.append(struct.pack("<L", block['bits']))
block_array.append(struct.pack("<L", block['nonce']))

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)

```

Next, I turned to the documentation:
<https://github.com/BTCGPU/BTCGPU/wiki/Technical-Spec>

This suggests that I need to add 3 more fields:

> nHeight, nReserved,nSolution

I believe that the code should look like this for bitcoingold:

```
block_array: List = list()
block_array.append(struct.pack('<L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("<L", block['height']))  # 632295
block_array.append(struct.pack("<L", block['reversed']))  # 0
block_array.append(struct.pack("<L", block['timestamp']))
block_array.append(struct.pack("<L", block['bits']))
block_array.append(struct.pack("<L", block['nonce'])))
block_array.append(struct.pack("B", block['solution']))

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)

```

But this does not work, because [nonce is not int.](https://www.reddit.com/r/BitcoinGoldHQ/comments/b3h34h/why_isnt_the_btg_nonce_numeric/?sort=top)

As a result of executing the code, should get this hash:
[00000003dd91f04483e990a1ecc5176abdfb18f40ae2ca6b0d203127bc150998](https://btgexplorer.com/block/00000003dd91f04483e990a1ecc5176abdfb18f40ae2ca6b0d203127bc150998)

How to convert "nonce" and "solution"?

**Tags:** python, block-header, bitcoin-gold

> **Comments:**
> **username_0**: Where can I ask questions about BitcoinGold? https://bitcoin.meta.stackexchange.com/questions/1041/where-can-i-ask-questions-related-to-bitcoingold  

---

## 1 answers

### Answer by username_0 on 2020-05-04. Score: 1 | Accepted answer

It is resolved.

```
block_array: List = list()
block_array.append(struct.pack('<L', block['version']))
block_array.append(bytes.fromhex(block['prev_block_hash'])[::-1])
block_array.append(bytes.fromhex(block['merkle_root'])[::-1])
block_array.append(struct.pack("<L", block['height']))  # 632295
block_array.append(bytes.fromhex(block['reserved']))  # 0
block_array.append(struct.pack("<L", block['timestamp']))
block_array.append(struct.pack("<L", block['bits']))
block_array.append(bytes.fromhex(block['nonce'])[::-1])
block_array.append(bytes.fromhex(block['solution'])[::-1])

header_hex: bytes = bytes.join(b'', block_array)
hash = double_sha256(header_hex)

```

Fun

```
def double_sha256(bytes_str: bytes):
    result = sha256(sha256(bytes_str).digest()).digest()
    return result[::-1]  # little endian

```


---

