Testing the createNewBlock method

Let's follow the below mentioned steps to test the createNewBlock method: 

  1. Firstly, underneath where we created our bitcoin variable, type in the following highlighted line of code:
const Blockchain = require('./blockchain');const bitcoin = new Blockchain();bitcoin.createNewBlock();console.log(bitcoin); 
  1. This createNewBlock() method requires three parameters, such as nonce, previousBlockHash, and a hash. For test purposes, we can just pass in whatever we want for now. Here, the nonce will just be a number. Then we will create a dummy hash for our previousBlockHash, followed by another hash for our hash parameter, as follows:
bitcoin.createNewBlock(2389,'OIUOEREDHKHKD','78s97d4x6dsf');

Right now, we are ...

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.