Bitcoin

How to calculate checksum of an address using Python

Lower bit range: 245
High bit range: 256

checksum of address 1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7 is 9ed6e860.


I tried the following, but it gave me incorrect results: 69e65f22

import hashlib
import base58
def calculate_checksum(address):
    # Decode the Base58 address
    decoded_address = base58.b58decode(address)
    # Get the address without the checksum
    address_without_checksum = decoded_address(0:-4)
    sha256_hash = hashlib.sha256(hashlib.sha256(address_without_checksum).digest()).digest()
    calculated_checksum = sha256_hash(:4)
       checksum = calculated_checksum.hex()
    return checksum
address = "1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7"
checksum = calculate_checksum(address)
print(checksum)

How is this calculated correctly using Python?

Related Articles

Back to top button