- 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 - Creating Genesis Block
We assume that the originator of TPCoins initially gives out 500 TPCoins to a known client Dinesh. For this, he first creates a Dinesh instance −
Dinesh = Client()
We then create a genesis transaction and send 500 TPCoins to Dinesh’s public address.
t0 = Transaction ( "Genesis", Dinesh.identity, 500.0 )
Now, we create an instance of Block class and call it block0.
block0 = Block()
We initialize the previous_block_hash and Nonce instance variables to None, as this is the very first transaction to be stored in our blockchain.
block0.previous_block_hash = None Nonce = None
Next, we will add the above t0 transaction to the verified_transactions list maintained within the block −
block0.verified_transactions.append (t0)
At this point, the block is completely initialized and is ready to be added to our blockchain. We will be creating the blockchain for this purpose. Before we add the block to the blockchain, we will hash the block and store its value in the global variable called last_block_hash that we declared previously. This value will be used by the next miner in his block.
We use the following two lines of coding for hashing the block and storing the digest value.
digest = hash (block0) last_block_hash = digest
Finally, we create a blockchain as we see in the next chapter.