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?