Python Blockchain Block Class
Python Blockchain Block Class
A block consists of a varying number of transactions. For simplicity, in our case we will
assume that the block consists of a fixed number of transactions, which is three in this case.
As the block needs to store the list of these three transactions, we will declare an instance
variable called verified_transactions as follows −
self.verified_transactions = []
We have named this variable as verified_transactions to indicate that only the verified valid
transactions will be added to the block. Each block also holds the hash value of the previous
block, so that the chain of blocks becomes immutable.
self.previous_block_hash = ""
Finally, we declare one more variable called Nonce for storing the nonce created by the
miner during the mining process.
self.Nonce = ""
class Block:
def __init__(self):
self.verified_transactions = []
self.previous_block_hash = ""
self.Nonce = ""
As each block needs the value of the previous block’s hash we declare a global variable
called last_block_hash as follows −
last_block_hash = ""
1 of 1 25/06/21, 18:22