Let's use the getBlock method inside of /block/:blockHash endpoint to retrieve a specific block by its blockHash. Let's follow these next steps to build the endpoint:
- The first thing that we want to do in this endpoint is to use the blockHash value that is sent with the /block/:blockHash request. We can access this blockHash on the req.params object. Go to the dev/networkNode.js file and in the /block/:blockHash endpoint that we defined previously, add the following highlighted code:
app.get('/block/:blockHash', function(req, res) {
const blockHash = req.params.blockHash;
});
Essentially, when we hit the /block/:blockHash endpoint, we're accessing the hash value of a block present on a particular node in the network. We're also accessing the hash value using the req.params object, which will give...