MetaMask – Huge Suggested Fees on MetaMask Post EIP-1559

gaslondonmetamaskreactweb3js

We have to react based app that is responsible for connecting with the NFT contract and calling the "mint" function.

To call the function, the contract will ask for 0.06ETH, and the amount is simply how many NFT's users want.

contract.methods.mintToken(amount).send({
                    from: account,
                    value: amount * web3.utils.toWei("0.06", "ether"),
                });

But metamask will set enormous number on gas limit, around 28500000 which is 10K or even 20K sometimes.

We tried to add custom gasLimit:

from: account,
value: amount * web3.utils.toWei("0.06", "ether"),
gasLimit: "300000",

Which gave a reasonable 150-200$.

But this transaction with this fee would fail some people, there is no pattern. We tried fetching the median value of the last blocks, dynamically increasing, etc. Nothing works, people still get reverted transactions even with a 500K gas limit, some are getting 200K transactions in seconds, really it's absolutely random.

So my question is:

How to reduce and make suggested fees reasonable?

And for a bit of advice, when I'm using gasLimit: "300000" should this be gasLimit: amount * "300000", since the user can mint as much as 20 in one transaction?

Best Answer

maxPriorityFeePerGas should normally be around 1.5 to 3.0 (2.5 is actually the setting that Web3js and Ethersjs use to account for 'MEV Heavy' blocks). This parameter is often incorrectly configured by metamask and will make the value the same as your maxFeePerGas, hence the crazy pricing.

You can use this API if you would like:

curl -sL api.txprice.com | jq

This API is a proxy to Blocknatives Gas Pricing Service. They have a chrome extension as well. (Note: my employer operates this endpoint, we do not track user data besides requests per min from IPs).

It will provide you with confidence interval-based pricing for transaction costs.

If you would like to see how other services/API providers produce their results here is a Gas Reporting Index (note: my own work):

https://github.com/sambacha/gas-reporting