Building the /consensus endpoint

Now, let's build the /consensus endpoint, which will use the chainIsValid method that we built in the previous section. Carry out the following steps to build the endpoint:  

  1. Let's go to networkNode.js file and, after the /register-node-bulk endpoint, define the /consensus endpoint as follows:
app.get('/consensus', function(req, res) { });
  1. Next, inside of the /consensus endpoint, let's make a request to every other node inside of the blockchain network to get their copies of the blockchain and compare them to the copy of the blockchain that's hosted on the current node that we're currently on:
app.get('/consensus', function(req, res) {        bitcoin.networkNodes.forEach(networkNodeUrl => {        });         });
  1. Inside of ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.