Creating the createNewTransaction method

The next method that we are going to add to our blockchain constructor function is called createNewTransaction. This method will create a new transaction for us. Let's follow the below mentioned steps to create the method: 

  1. Start building up this method by adding the following line of code after our getLastBlock method:
Blockchain.prototype.createNewTransaction = function () {}
  1. The function () will take three parameters, such as the following:
Blockchain.prototype.createNewTransaction = function (amount, sender, recipient) {}

What these three parameters will do is as follows: 

  • amount: This parameter will take in the amount of the transaction or how much is being sent in this transaction.
  • sender ...

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.