Refactoring the /mine endpoint

 Let's refactor the /mine endpoint by implementing the following steps:

  1. Head over to the dev/networkNode.js file. In the /mine endpoint, beneath the part where we had defined the newBlock variable, let's add the functionality to broadcast the new block to all the other nodes in the network. To do this, follow the same process that we introduced in the previous sections—that is, to loop through all the other nodes inside the network, make a request to the nodes, and send the newBlock variable as data:
bitcoin.networkNodes.forEach(networkNodeUrl => {})

The preceding line mentions that for each of the networkNodes, we're going to make a request and send along the newBlock

  1. We then need some request options ...

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.