简体   繁体   中英

Function Parameters with Node.js Promise

I'm using blockexplorer API for blockchain, and I want to get block data based on specific hash (This hash should be taken from another function).

I'm new with using Promise, So can anyone help me to get the block data?

This is my code:

const be = require('blockexplorer');

be.block(be.blockIndex(0))
.then((result) => {
 console.log(result)
})
.catch((err) => {
throw err
})

Also, I've tried another way with using nested Promise but it didn't work.

You can make a promise.then return a promise and chain it further. Modify the code to this.

be.blockIndex(0)
.then((result) => be.block(result))
.then((result) => {
   console.log(result)
})
.catch((err) => {
   console.log("Error Occurred: ", err); // Don't throw the error instead handle it
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM