ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Ethers Makes Unnecessary getGasPrice Request in populateTransaction Method for Legacy Transactions

Open IvanKodak opened this issue 10 months ago • 5 comments

Ethers Version

6.13.5

Search Terms

populateTransaction

Describe the Problem

Hello,

I noticed that Ethers requests the gas price in the populateTransaction method even when it is already provided in the arguments.

Could you please review the code snippet I attached? I think need to add a check similar to the EIP-1559 transaction scenario: if feeData is provided through function arguments, the request for it should be skipped.

Code Snippet

if ((pop.type === 2 || pop.type == null) && (pop.maxFeePerGas != null && pop.maxPriorityFeePerGas != null)) {
            // Fully-formed EIP-1559 transaction (skip getFeeData)
            pop.type = 2;

        } else if (pop.type === 0 || pop.type === 1) {
            // Explicit Legacy or EIP-2930 transaction

            // We need to get fee data to determine things
            const feeData = await provider.getFeeData();

            assert(feeData.gasPrice != null, "network does not support gasPrice", "UNSUPPORTED_OPERATION", {
                operation: "getGasPrice" });

            // Populate missing gasPrice
            if (pop.gasPrice == null) { pop.gasPrice = feeData.gasPrice; }

        }

Contract ABI


Errors


Environment

No response

Environment (Other)

No response

IvanKodak avatar Feb 06 '25 11:02 IvanKodak

Off the top of my head, this sounds fair. I’ll look into it tomorrow for the upcoming minor release. :)

ricmoo avatar Feb 06 '25 11:02 ricmoo

Off the top of my head, this sounds fair. I’ll look into it tomorrow for the upcoming minor release. :)

Thanks

IvanKodak avatar Feb 06 '25 12:02 IvanKodak

Happy to watch someone else pointing out the issue https://github.com/ethers-io/ethers.js/issues/4687, hope the polygon support could be also fixed as the polygon oracle formula is also somewhat similar with default maxPriorityFeePerGas ( both oracle and rpc method uses eth_feeHistory inside ) https://github.com/ethers-io/ethers.js/issues/4909

tornadocontrib avatar Feb 08 '25 11:02 tornadocontrib

@ricmoo, maybe you have some updates on this ?

DmytroShalaiev avatar Feb 17 '25 10:02 DmytroShalaiev

@ricmoo ping

IvanKodak avatar May 13 '25 11:05 IvanKodak