Author

Topic: I Want To Learn Exact Formula To Get Block's Hash (Read 193 times)

sr. member
Activity: 310
Merit: 727
---------> 1231006505
September 25, 2018, 05:53:00 AM
#4
You are a legend dude. I would give merit if I had but where is the nonce?
This is the nonce in the example provided by seoincorporation: 42a14695

Code:
version        = "01000000"
hashPrevBlock  = "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000"
hashMerkleRoot = "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b"
Time       = "c7f5d74d"
Bits       = "f2b9441a"
Nonce       = "42a14695"


newbie
Activity: 9
Merit: 0
Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin

This is what you are looking for:

Quote
A block header contains these fields:
Field    Purpose    Updated when...    Size (Bytes)
Version    Block version number    You upgrade the software and it specifies a new version    4
hashPrevBlock    256-bit hash of the previous block header    A new block comes in    32
hashMerkleRoot    256-bit hash based on all of the transactions in the block    A transaction is accepted    32
Time    Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds    4
Bits    Current target in compact format    The difficulty is adjusted    4
Nonce    32-bit number (starts at 0)    A hash is tried (increments)    4

For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, Block 125552. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:

Code:
>>> import hashlib
>>> header_hex = ("01000000" +
 "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
 "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
 "c7f5d74d" +
 "f2b9441a" +
 "42a14695")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
>>> hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'

Source: https://en.bitcoin.it/wiki/Block_hashing_algorithm

You are a legend dude. I would give merit if I had but where is the nonce?
legendary
Activity: 2982
Merit: 2681
Top Crypto Casino
Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin

This is what you are looking for:

Quote
A block header contains these fields:
Field    Purpose    Updated when...    Size (Bytes)
Version    Block version number    You upgrade the software and it specifies a new version    4
hashPrevBlock    256-bit hash of the previous block header    A new block comes in    32
hashMerkleRoot    256-bit hash based on all of the transactions in the block    A transaction is accepted    32
Time    Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds    4
Bits    Current target in compact format    The difficulty is adjusted    4
Nonce    32-bit number (starts at 0)    A hash is tried (increments)    4

For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, Block 125552. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:

Code:
>>> import hashlib
>>> header_hex = ("01000000" +
 "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
 "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
 "c7f5d74d" +
 "f2b9441a" +
 "42a14695")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
>>> hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'

Source: https://en.bitcoin.it/wiki/Block_hashing_algorithm
newbie
Activity: 9
Merit: 0
Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin
Jump to: