gpt4 book ai didi

node.js - Node Js中如何选择首先调用哪个函数

转载 作者:太空宇宙 更新时间:2023-11-04 02:55:43 24 4
gpt4 key购买 nike

我目前正在使用 Ether 包和 NodeJS 来学习一些东西。

这是我的代码:

var ethers = require('ethers');
var providers = require('ethers').providers;

var infuraProvider = new providers.InfuraProvider(process.argv[3]);

infuraProvider.getBlockNumber().then(function(blockNumber) {
console.log("Current block number: " + blockNumber);
});

infuraProvider.getGasPrice().then(function(gasPrice) {
console.log("Current gas price: " + gasPrice.toString());
});

它基本上从我的参数中获取网络,然后获取blockNumber和gasPrice。因此,如果运行这个,我会得到以下结果:

Current block number: 5083149
Current gas price: 8000000000

这就是我想要的。但有时,它会在区 block 号之前给出天然气价格,如下所示:

Current gas price: 8000000000
Current block number: 5083149

如何编辑我的代码,使其始终首先给出 block 号?我尝试使用 .then 关键字,但没能成功。

谢谢

最佳答案

试试这个

infuraProvider.getBlockNumber().then(function(blockNumber) {
console.log("Current block number: " + blockNumber);
return infuraProvider.getGasPrice();
}).then(function(gasPrice) {
console.log("Current gas price: " + gasPrice.toString());
});

关于node.js - Node Js中如何选择首先调用哪个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48768541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com