I am currently using an Ether package and NodeJS to learn a few things.
Here is my code:
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());
});
It basically gets the network from my argument, and then get blockNumber and gasPrice. So if run this, here is what I get:
Current block number: 5083149
Current gas price: 8000000000
Which is what I want. But sometimes, it gives the gas price BEFORE the block number, like that:
Current gas price: 8000000000
Current block number: 5083149
How can I edit my code so it always give the block number first? I tried to play with the .thenkeyword, but didn't manage to make it work.