我正在为区块链使用blockexplorer API,我想基于特定的哈希值获取块数据(此哈希值应取自另一个函数)。
我是Promise的新手,那么有人可以帮助我获取区块数据吗?
这是我的代码:
const be = require('blockexplorer');
be.block(be.blockIndex(0))
.then((result) => {
console.log(result)
})
.catch((err) => {
throw err
})
此外,我还尝试了另一种使用嵌套Promise的方法,但是它没有用。
答案 0 :(得分:0)
您可以使promise.then
返回一个诺言并将其进一步链接。修改此代码。
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
});