2

I'm executing transactions on mainnet with a NodeJS script:

async function send(web3, transaction, destAddr, gasPrice, privateKey) {
    const options = {
        data    : transaction.encodeABI(),
        to      : destAddr,
        gasPrice: gasPrice,
        gas     : (await web3.eth.getBlock("latest")).gasLimit
    };
    const signed  = await web3.eth.accounts.signTransaction(options, privateKey);
    const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
    return receipt;
}

Every transaction takes ages to complete.

I keep raising the gas-price, but no improvement.

I've finally tried to reduce the gas-limit, and instead of taking the max gas-limit per block, I just wrote "500000", which is far less than the block gas-limit, but far more than the actual gas required for each transaction.

All of the sudden, the network has started to process my transactions much faster.

It feels as if a high gas-limit "scares off" miners or something.

I've tried using await transaction.estimateGas() but it's been giving me a "gas required exceeds allowance or always failing transaction" error every time.

I believe that this is possibly because this function underestimates the actual gas required for the transaction, so I am somewhat reluctant to use it.

Would anyone here be able to shed some light on this?

Thank you!

4

In short: It's exactly as you suspect, a higher gas limit means your transaction is less likely to be included by miners.

The reasoning: miners seek to maximize their profit within each block. Calls to eth_estimateGas can be computationally heavy, so miners typically do not determine the actual gas each tx will consume. Instead they calculate gasPrice * gasLimit for each given transaction and from that determine the most cost-effective set of transactions to mine.

If you are setting the gas limit to be == the block gas limit, you will need to offer a very high gas price in order for your tx on it's own to be more profitable than all other possible combinations of pending transactions.

  • Excellent answer. I just got a very similar explanation from a friend. Thank you very much!!! – goodvibration Oct 7 '19 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.