Friday, November 22, 2024

blockchain – How do you confirm a block manually?

Copied under is a brief python script that walks via the verification, utilizing enter values for block 505400 from the blockchain.com block explorer:

import json
import hashlib

block={}

#inputs values (from https://www.blockchain.com/explorer/blocks/btc/505400)
block['blocknumber']=505400
block['version']='20000000'
block['hashPrevBlock']='00000000000000000022a664b3ff1e4f85140eddeebd0efcbe6a543d45c4135f'
block['hashMerkleRoot']='a3defcaa713d267eacab786c4cc9c0df895d8ac02066df6c84c7aec437ae17ae'
block['time']=1516561306
block['bits']=394155916
block['nonce']=2816816696

#put together values
block['versionprepared']=bytes.fromhex(block['version'])[::-1].hex()
block['hashPrevBlockprepared']=bytes.fromhex(block['hashPrevBlock'])[::-1].hex()
block['hashMerkleRootprepared']=bytes.fromhex(block['hashMerkleRoot'])[::-1].hex()
block['timeprepared']=int(block['time']).to_bytes(4, byteorder="little").hex()
block['bitsprepared']=int(block['bits']).to_bytes(4, byteorder="little").hex()
block['nonceprepared']=int(block['nonce']).to_bytes(4, byteorder="little").hex()

#concatentate ready values to create enter to double sha256 hash operate
block['hashinput']=block['versionprepared'] + block['hashPrevBlockprepared'] + block['hashMerkleRootprepared'] + block['timeprepared'] + block['bitsprepared'] + block['nonceprepared']

#double sha256 hash
block['hashoutcomputed']=(hashlib.sha256(hashlib.sha256(bytes.fromhex(block['hashinput'])).digest()).digest())[::-1].hex()

#print outcomes
print(json.dumps(block, indent=4))

The double sha256 hash computed is:

00000000000000000023b89dd18f6be5a6c03a71cd864ccbdf024683114b9ce3

As anticipated, this consequence has 18 main zeroes (as required to satisfy the problem requirement for this block), and matches the hash for block 505400 based on the block explorer.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles