Metamask defaulting to too high of gas fee #2796
-
I have a function - lets call it "buy". It allows the user to deposit some eth and in return gains some functionality with the smart contract. The function costs ~300K gas (confirmed both by gas-report.txt and by trying it on goerli). However, when I try to use useWeb3Contract from react-moralis and embed that function in a button on my front end, metamask defaults to a gas limit of ~29M. This can be problematic if a user thinks they will have to pay more gas than they ultimately will and decides not to go ahead with the tx. Does anyone know how to instruct metamask to use a lower gas limit in this case? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
@tmcdonough Not sure where the problem is either in the contract code or in metamask settings. You can check both. |
Beta Was this translation helpful? Give feedback.
-
You can leave a note to the users on the front-end for the following: When this is enabled (in Metamask), the user can select the gas limit by themselves (whenever they send a txn) and not have to be suspicious of your dApp. |
Beta Was this translation helpful? Give feedback.
-
@alymurtazamemon @krakxn I think i found the root of the problem... When I deploy a contract using hardhat, I have a script that exports the ABI to my frontend directory (constants folder) - as was done in the tutorial. I noticed that when I deploy to a mainnet (e.g. Avalanche), the ABI doesn't include a "gas" field for each contract function. This is good. E.g.:
But when I simply run "hh deploy" it adds a gas limit to the ABI, which my frontend then uses for all chains.
So this ends up overwriting the ABI my frontend is using and it attempts to call that function with a higher gas limit. I double checked my solidity project and I don't have reference to any 29M gas limit anywhere (looked in both hardhat config and helper hardhat config). Obviously I could have different ABIs for each chain to fix the problem, but now I'm just curious why hardhat is doing this for 31337 chain. Any ideas why this is defaulting / how to change this programmatically? Thanks! |
Beta Was this translation helpful? Give feedback.
@tmcdonough Not sure where the problem is either in the contract code or in metamask settings. You can check both.