How to increase gas limit on a transaction?

Is it possible to specify the gas limit that the user allows to use for a specific transaction, when using:

Moralis.executeFunction(options);

it is not possible from what I know to set that gas limit with executeFunction

usually you don’t have to change that limit, as metamask will run gas estimation to set that value

Thanks for the fast answer!
Hmm, ok, because I’m trying to simulate an iteration on a list with more than 10k elements (as if I have 10k users tracked on my contract), but I got this error:

image

Anything I can do to fix this? I’m using remix.ethereum.org, but I got the same error if I try to call the function with Moralis

that usually means that the transaction will fail with an exception and you have to find out why it will fail

I just tried to do a for cycle with 50k iterations and I increased a counter every time. But yeah, I guess you can’t do huge for loop on a smart contract

You have an issue with your contract. Probably, you are trying to deploy on testnet?

Yeah I’m on testnet. But I don’t think there is anything wrong with my test code. You can take a look if you want:

contract Test {
    
    uint256 public iterations = 0;

    function tryGasException() external{
        
        while(iterations< 50000) {
            
            iterations++;
        }
    }
}

I can only do 12k iterations without getting an error

you can set a different gas limit in metamask before sending the transaction

Thank you, I was just curious to know if it was possible to set it by code, so that the user doesn’t have to change it manually, but apparently I can’t :grin:

I think that you may be able to do that if you use web3 directly and not executeFunction

Try to deploy on mainnet (you don’t have to approve the transaction) and it will go through.