MetaMask calculated automatically the gas needed for every transaction, but for one in particular, it always returns the error "out of gas" if I use the default amount.

The function is really simple so I don't get how it can run out of gas:

mapping (uint => xyz) public xyzs;

function setXyzParameters(uint id, uint newPrice, bool _isForSale) public {
    require(msg.sender == xyzs[id].creator);
    xyzs[id].price = newPrice;
    xyzs[id].isForSale = _isForSale;

On my private node, MetaMask sets by default a gas limit of 27043 and it fails if I leave it at that, 30000 still fails but it works 40000.

What am I doing wrong?

Additional info: Turns out the amount of gas is different if the boolean is true or false. I guess when it's false some part of the Tx data is 00000000 while it's more info if it's true, so maybe that's why the estimated gas is different.

(To give context, I'm working on something based on the Truffle tutorial)


Your Answer

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

Browse other questions tagged or ask your own question.