forex.pm forex forum binary options trade

 Š”ryptocurrency exchanges => Binance - Š”ryptocurrency exchanges => Topic started by: Bitcoin on Feb 10, 2022, 09:43 am

Title: Calculation of the hash of a block
Post by: Bitcoin on Feb 10, 2022, 09:43 am
Calculation of the hash of a block

Please help me to calculate the hash of the block 722460. I have this block header:


  "hash": "00000000000000000002b73f69e81b8b5e98dff0f2b7632fcb83c050c3b099a1",
  "confirmations": 9,
  "height": 722460,
  "version": 536879108,
  "versionHex": "20002004",
  "merkleroot": "e1e0573e6098d8128ee859e7540f56b01fe0a33e56694df6d2fab0f96c4954b3",
  "time": 1644403033,
  "mediantime": 1644398983,
  "nonce": 1693537958,
  "bits": "170a8bb4",
  "difficulty": 26690525287405.5,
  "chainwork": "000000000000000000000000000000000000000028664e27abbdcf002a673476",
  "nTx": 3371,
  "previousblockhash": "00000000000000000009d54a110cc122960d31567d3ee84a1f18a98f50591046",
  "nextblockhash": "0000000000000000000a6bf48e80b7b873998e9b8e7c4ced6ec85d559bce72df",
  "strippedsize": 821777,
  "size": 1534464,
  "weight": 3999795,

To calculate hash I need theese values (already have converted them):


version: '04200020'
previousblockhash: '461059508fa9181f4ae83e7d56310d9622c10c114ad509000000000000000000'
merkleroot: 'b354496cf9b0fad2f64d69563ea3e01fb0560f54e759e88e12d898603e57e0e1'
time: '3330404416'
bits: 'b48b0a17'
nonce: 'a656f164'

Now I am trying to calculate the hash:


import hashlib
from binascii import unhexlify, hexlify
header_hex = ("04200020" +
 "461059508fa9181f4ae83e7d56310d9622c10c114ad509000000000000000000" +
 "b354496cf9b0fad2f64d69563ea3e01fb0560f54e759e88e12d898603e57e0e1" +
 "3330404416" +
 "b48b0a17" +
 "a656f164")
header_bin = unhexlify(header_hex)
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
hexlify(hash[::-1]).decode("utf-8")

And all I get is:
b3e5b3485f11963cff6659fb48cfecc6e1cda271324d8b25b1af023205bb891b


Instaed of:
00000000000000000002b73f69e81b8b5e98dff0f2b7632fcb83c050c3b099a1


Please tell me what am I doing wrong?


Thank you in advance


Source: Calculation of the hash of a block (https://bitcoin.stackexchange.com/questions/112329/calculation-of-the-hash-of-a-block)