function payMe() payable{
    // doing some stuff with `msg.value`

    users[msg.sender].balance += modifiedMsgValue ;

In the above code what if gas runs out on the second line? so there will be no gas left to update user's data and add the ETH to the user's balance.

will the function be reverted and will the ETH returns back to the user? if not, what is the solution for such scenario?

is there a way to estimate the gas usage for the function and if there is not enough gas just revert the function?

1 Answer 1


The whole function will revert and the ether will be returned to the sender minus the cost of the transaction.

Your Answer

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

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