Creating a genesis block

One more thing that we would have to add to our blockchain data structure is the genesis block. But what is a genesis block? Well, a genesis block is simply the first block in any blockchain.  

 To create our genesis block, we are going to use the createNewBlock method inside of the Blockchain() constructor function. Go to the dev/blockchain.js file, and inside of the blockchain constructor function type in the following highlighted lines of code:

function Blockchain () {    this.chain = [];    this.pendingTransactions =[];    this.createNewBlock();         }

As we observed in the previous section, the createNewBlock method takes in the value of a nonce, a previousBlockHash, and a hash as parameters. Since we're using the createNewBlock ...

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.