<pre><code>import hashlib
import base58
def calculate_checksum(address):
    decoded_address = base58.b58decode(address).hex()
    print(f&quot;Checksum of {address} is {decoded_address[-8:]}&quot;)
    address_without_checksum = decoded_address[0:-8]
    sha256_hash = hashlib.sha256(hashlib.sha256(bytes.fromhex(address_without_checksum)).digest()).digest()
    calculated_checksum = sha256_hash[:4]
    checksum = calculated_checksum.hex()
    return checksum

address = &quot;1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7&quot;
checksum = calculate_checksum(address)
print(f&quot;The calculated checksum is {checksum}&quot;)
</code></pre>

CC BY-SA 4.0
2024-01-11T19:43:15.240Z
2024-01-11T19:43:15.240Z
leslie
<p>Lower Bit Range:      245<br />
Upper Bit Range:      256</p>
<p>The Checksum of address <code>1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7</code> is <code>9ed6e860</code>.</p>
<hr />
<p>I tried the following but got incorrect result <code>69e65f22</code></p>
<pre><code>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 = &quot;1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7&quot;
checksum = calculate_checksum(address)
print(checksum)
</code></pre>
<p>How is it correctly calculated using python?</p>

CC BY-SA 4.0
2024-01-05T16:55:00.880Z
Instead of adding requested details in comments, simply [edit] your answer with the items.  Take a look at the change I made to your question to see how I was able to format the code you added.
Hannah Vernon
<address><checksum>
How to calculate checksum of Address using Python
Murphy Celestine
# How to calculate checksum of Address using Python

(Asked by: username_0 on 2023-12-23)

Lower Bit Range: 245  
Upper Bit Range: 256

The Checksum of address `1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7` is `9ed6e860`.

---

I tried the following but got incorrect result `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 it correctly calculated using python?

**Tags:** address, checksum

> **Comments:**
> **username_1**: Instead of adding requested details in comments, simply [edit] your answer with the items.  Take a look at the change I made to your question to see how I was able to format the code you added.  

---

## 1 answers

### Answer by username_2 on 2024-01-11. Score: 0

```
import hashlib
import base58
def calculate_checksum(address):
    decoded_address = base58.b58decode(address).hex()
    print(f"Checksum of {address} is {decoded_address[-8:]}")
    address_without_checksum = decoded_address[0:-8]
    sha256_hash = hashlib.sha256(hashlib.sha256(bytes.fromhex(address_without_checksum)).digest()).digest()
    calculated_checksum = sha256_hash[:4]
    checksum = calculated_checksum.hex()
    return checksum

address = "1H5aq8vssj9fCKdw2mYEn8enzpUMEBsUZ7"
checksum = calculate_checksum(address)
print(f"The calculated checksum is {checksum}")

```


---

