1

Using Solidity 0.4.18. If I send ether to a payable function, and the function does some of its stuff, and then throws (via require), what happens to the ether that was sent to it? Does the ether stay in the contract?

Edit: I know that "throw" reverts transactions - I wanted to know whether "require" does the same.

2
  • I understand a similar question was answered here: ethereum.stackexchange.com/questions/6032/…. Does it happen the same way when using "require" instead of "throw"?
    – neuromouse
    Commented Dec 10, 2017 at 19:24
  • Yes, revert and throw generate the same opcode REVERT.
    – Ismael
    Commented Dec 10, 2017 at 20:53

1 Answer 1

2

When a contract is firing an exception (via throw / require / assert), the transaction and all change to the state are reverted . So the ether that you sent to this function will not be transferred .

Internally, Solidity performs a revert operation (instruction 0xfd) for a require-style exception and executes an invalid operation (instruction 0xfe) to throw an assert-style exception. In both cases, this causes the EVM to revert all changes made to the state.

(from official doc)

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