Block hashes are used to uniquely identify and maintain the integrity of each block. The SHA-256 algorithm is used to generate the hash of the block using the timestamp, data, and previous hash — the three properties of our Block class!
Let’s create the
.generate_hash() method for the Block class.
.generate_hash() method, create the variable
block_contents, which combines the
Block timestamp, transactions, nonce, and previous hash.
Wrap each item in the
str() method in order to convert them to a string type to prepare for hashing.
Return the result.
Create a variable
Create a new hash with
block_contents and save the value to
Remember to use the
.encode() method to encode the string.
Update the method to return
Return the text hash value by calling the
hexdigest() method on
Uncomment the line in
__init__() that calls the
generate_hash() function to complete the