- Python Blockchain Tutorial
- Python Blockchain - Home
- Python Blockchain - Introduction
- Blockchain - Developing Client
- Blockchain - Client Class
- Blockchain - Transaction Class
- Creating Multiple Transactions
- Blockchain - Block Class
- Blockchain - Creating Genesis Block
- Blockchain - Creating Blockchain
- Blockchain - Adding Genesis Block
- Blockchain - Creating Miners
- Blockchain - Adding Blocks
- Blockchain - Scope & Conclusion
- Python Blockchain Resources
- Python Blockchain - Quick Guide
- Python Blockchain - Resources
- Python Blockchain - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.