Let's build a new method called getBlock that will take the given blockHash and search the entire blockchain for the block associated with that particular hash. In order to build the getBlock method, follow these steps:
- Go to the dev/blockchain.js file and after the chainIsValid method, define this new method as follows:
Blockchain.prototype.getBlock = function(blockHash) {
};
- Inside this method, we want to iterate through the entire blockchain and search for the block that has a particular blockHash value. Then, this method will return that specific block to us. We're going to do all this with the help of a for loop:
Blockchain.prototype.getBlock = function(blockHash) {
this.chain.forEach(block => {
});
};
When defining the for loop, we cycle through every single block in the blockchain.
- Next, inside the loop, mention...