Send limitgas to metamask

Hi everybody.

how I can set a gas limit for transaction with hardhat enviroment.

With window.ethereum.request method in the App.js?

Or would it have to be implemented in the solidity contract?

Not in the Solidity contract. In window.ethereum.request it would work. If you're using Ethers.js or Web3.js there is probably also a way to set a gas limit when you set a transaction and/or a default global limit.

Thanks @frangio .

But when you have a somewhat large contract, a token with a certain complexity, that needs a higher limit gas, you cannot send a higher limit gas to the user from the contract, right? Since that token needs more than 100000 gaslimit that is usually had by default in the metamask. What I suspect is that the choice of the gas limit is a customization of the user. And if our token needs more gas, it will have this problem. Many users will fail because of their lower gas limit and that can not be anticipated

Wallets will estimate how much gas is required for a particular transaction. So this shouldn't be an issue.

The problem is to prevent a newbie from freaking out. When a transaction is made and the gas limit is low, it will not be executed. This can scare the person who is unfamiliar with these points. Being true that it is an issue that each user has to know, in this new economic relationship, I would like the use of the token to have already suggested the gas limit they need. Because in my case, the contract is relatively expensive. You need a limit of 300000. I just wanted to know if this can be sent within the contract so that the wallet takes it into account.

It can't be set from within the contract. But the newbie's wallet should automatically estimate and set the correct gas limit. Have you tested this manually?

Yes, I have verified that metamask calculates or estimates the gas required for a contract. But sometimes if you have a set gas limit, it remains as is logical. How does metamask know the recommended gas limit for a contract token?

The JSON RPC of a node has an "estimate gas" method that they use.

Do you know if we have an article or thread here in the forum that talks in detail about this use of JSON RPC for these purposes?

I haven't seen any. You can search online for the eth_estimateGas RPC method and related concepts.

Ok.
Tkanks for your time.