I have a function:

function test(uint value) {
    if (balances[msg.sender] < value)

    balances[msg.sender] -= value;

*note: the above is for illustrative purposes only. Security and safe maths is not a concern.

I understand that reading from the blockchain only consume 0 gas, for View and Pure function.

So my question is: For the function above will I have to pay for gas if I have insufficient balance and return early (no transaction made).


If no transaction is made then there is no fee; however, since there is no transaction, the balances[msg.sender] update wont be saved to the state.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.