Now we can use the code in our previous exercise to spot a broken link. Let’s try tampering with the contents of the block and see how that creates a mismatch between hash values.
Instantiate a new Blockchain object called my_blockchain
.
Add a new block to my_blockchain
and pass in new_transactions
as the argument.
Print out the contents of my_blockchain
to see the new block!
Remember, the .add_block()
method is used to add a block. This method has new_transactions
as its parameter. Similarly, the print_blocks()
method is used to print the contents of a Blockchain object.
Select the transactions found in my_blockchain
‘s chain
attribute. Set the transactions
variable of Block 1 to the string "fake_transactions"
.
Use my_blockchain.chain[1]
to grab Block 1 on the blockchain. You can access this block’s transactions using the transactions
attribute.
Now let’s check if the blockchain is still valid by calling the correct method on my_blockchain
!
Remember, the validate_chain()
method is used to validate a Blockchain object.