- Blockchain - Scope & Conclusion
- Blockchain - Adding Blocks
- Blockchain - Creating Miners
- Blockchain - Adding Genesis Block
- Blockchain - Creating Blockchain
- Blockchain - Creating Genesis Block
- Blockchain - Block Class
- Creating Multiple Transactions
- Blockchain - Transaction Class
- Blockchain - Client Class
- Blockchain - Developing Client
- Python Blockchain - Introduction
- Python Blockchain - Home
Python Blockchain Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python Blockchain - Block Class
A block consists of a varying number of transactions. For simppcity, 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 pst 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 vapd 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.
Advertisements