Each computer participant has their own copy of the blockchain. Ideally, each copy of the blockchain should have the same properties and functionality to add and validate blocks.
We can represent the blockchain as an object. We are using objects for our implementation, because they offer the flexibility to create specific attributes and methods. Representing it as an object also allows us to create blockchain instances for each computer participant.
To review, our blockchain contains the following:
- Chain: A list that holds all the blocks inside the blockchain.
- Unverified Transactions: A list that represents all the unverified transactions before being passed into a block.
- Genesis Block: A block automatically generated when the blockchain is initialized.
Fill in the
__init__() method inside the
Blockchain class by initializing instance variables
all_transactions as empty Python lists.
Complete the method
genesis_block by instantiating a new
Block object with an empty
transactions list and a previous hash of
Append the resulting block to the
Since we want to automatically create a Genesis Block when a new blockchain object is created, call the method
.genesis_block() inside the