Imagine I have a function that looks something like this. Is the ether refunded to the sender (invoker) if require fails?

function foo(uint _minShares) public {
        uint256 ethReserveBeforeDeposit = address(this).balance - msg.value;
        // compute proportion of deposited ether and total ether balance to determine amount of shares
        uint256 sharesMinted = (msg.value / ethReserveBeforeDeposit) * totalSupply();
        require(sharesMinted >= _minShares);
        // what happens if require fail, is msg.value refunded?

1 Answer 1


Just tested it out on remix.ethereum

  • first of all the foo function must have the keyword payable to receive ether
  • If require fails the the initial sent ether to foo function will be refunded but gas will still be used till the require statement is reached.

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.