0

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?

4
  • Can you add screenshots from metamask for those 2 ways and your mint function's code? Sep 3, 2021 at 16:59
  • Not sure why, but if the tokens are already minted it those that error
    – 0xsegfault
    Sep 3, 2021 at 18:59
  • Yep, i will add screenshot later today.
    – Kaneda
    Sep 3, 2021 at 20:51
  • No, it's not fully minted. Still 20% to go. And if you modify fees to lower value, you can mint easily. But we can't adjust gas for each user since one single value doesn't works for everybody.
    – Kaneda
    Sep 3, 2021 at 20:52

2 Answers 2

1

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

0

We've fixed the problem by setting maxFeePerGas and maxPriorityFeePerGas on null

contract.methods.methodName().send({
                        ...
                        maxPriorityFeePerGas: null,
                        maxFeePerGas: null,
                    });

and for the last part - yes, amount needs to be multiplied on gas limit.

Your Answer

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

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