Is there a global gasPrice parameter?

Hi there,just wondering if there is a global minimum gasPrice parameter on BSC or BSC Testnet. The most recent gasPrice I got on BSC testnet is 10 GWei. I tried to manually set it as 1 GWei and got a “transaction underpriced” error. Is there any way of knowing the minimum gasPrice prior to the actual transaction happening?

Hey! In all EVM networks (BSC included), there is a gasPrice function you can call that will return an estimate of the gas price you can use for getting your transaction mined. See Both web3js and ethers.js have functions to call into this method.

1 Like

Hi @spalladino , I was able to retrieve gasPrice using the code given above in the hardhat console, however, the returned value is for Ethereum network when I specified the network to be bsctestnet . Wondering how I can get gasPrice for bsctestnet instead of ethereum.

I could tell it’s the number from Ethereum, because await provider.getBlockNumber(); returns a number close to 12604172 which is the block height of Ethereum mainnet.

var providers = ethers.providers;
var provider = providers.getDefaultProvider();
provider.getGasPrice().then(function(gasPrice) {
    gasPriceString = gasPrice.toString();
    console.log("Current gas price: " + gasPriceString);

If you’re using hardhat, make sure you’ve registered a connection to bsctestnet in your hardhat config file, and then start the console as hardhat console --network bsctestnet.

Hi @spalladino , just checked with Hardhat team, the trick is "use the provider injected by hardhat, that is under hre.ethers.provider . That one is going to be connected to the network you selected with --network". Cheers!

1 Like