0% found this document useful (0 votes)
15 views

Python Blockchain Block Class

The document describes a Block class for a Python blockchain. The Block class contains three instance variables - verified_transactions to store up to 3 transactions, previous_block_hash to link the block to the previous one in the chain, and Nonce set by the miner during mining. It also defines a global last_block_hash variable to hold the hash of the previous block.

Uploaded by

Shrivas SP
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Python Blockchain Block Class

The document describes a Block class for a Python blockchain. The Block class contains three instance variables - verified_transactions to store up to 3 transactions, previous_block_hash to link the block to the previous one in the chain, and Nonce set by the miner during mining. It also defines a global last_block_hash variable to hold the hash of the previous block.

Uploaded by

Shrivas SP
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Blockchain - Block Class - Tutorialspoint https://www.tutorialspoint.com/python_blockchain/pyt...

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.

To store the previous hash, we declare an instance variable as follows −

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 = ""

The full definition of the Block class is given below −

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 = ""

Now let us create our first block in the blockchain.

1 of 1 25/06/21, 18:22

You might also like