2

I am using Web3JS 1.0+ to send transactions to my smart contract.

I've been using the following constant for the gas price in my code that I got a long time ago from a tutorial. What is the "professional" strategy for determining what gas price to pass to sendSignedTransaction() on the Ganache, Rinkeby and main networks?

What Web3JS method(s) do I call to determine the correct gas price? Note, in my dApp paying a bit extra for gas is the preferred choice over trying to save some money on gas at the risk of transactions mining more slowly.

const DEFAULT_GAS_PRICE_GWEI = '0x09184e72a000';

I found the following post on the subject, but I'm wondering if there is something more nuanced:

How to caculate/estimate Gas Limit and Gas Price based on current state of the ether network?

The top answer on that post outlines the technique of using the gas price found in recent blocks or using the gas price oracle available from Web3JS, which uses the median value for the gas price found across recent blocks. My concern with using the median value is that if there is a temporary surge in gas price you could end up with orphan or slow transactions on the network that were submitted before the gas price surge.

1
  • I think the median/average values are the 'best ways' to go because that's the ideal and most likely situation. The dreaded surge you are worried about should be an unusual behavior in the network, and only then will you have to worry about some ways to handle it.
    – DaveIdito
    Commented Nov 17, 2018 at 21:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.