Creating the proofOfWork method

Let's build out the proofOfWork method, which we discussed in the preceding section:

  1. After the hashBlock method, define the proofOfWork method as follows: 
Blockchain.prototype.proofOfWork = function() {}
  1. This method takes in two parameters: previousBlockHash and currentBlockData
Blockchain.prototype.proofOfWork = function( previousBlockHash, currentBlockData) { }
  1. The first thing that we want to do inside of our method is define a nonce:
Blockchain.prototype.proofOfWork = function( previousBlockHash, currentBlockData) {     let nonce = 0;}
  1. Next, we want to hash all of our data for the first time, so type in the following highlighted line of code: 
Blockchain.prototype.proofOfWork = function( previousBlockHash, ...

Get Learn Blockchain Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.