6

If a contract throws a exception (using 'throw') is any ether sent by the contract to other contracts or external accounts also reverted?

I understand that any contract callers have the ether value returned (refunded) but I am unsure what happens to the contract ether balance when sending ether to other contracts or accounts.

1 Answer 1

5

Everything, with a handful of exceptions, is reverted. Balance changes, contract state changes, state changes in other contracts, you get the picture.

It's almost as if the transaction never happened. Here's the handful of exceptions:

  • The gas is still spent. (In fact, all of it is.)
  • The transaction still occupies space in the block. Anyone can see what happened to the transaction.
  • The nonce of the account that sent the transaction is increased, to prevent replay attacks.

Additional details on throw best practices can be found in this blog post.

4
  • 1
    Thanks for the answer. I have one question though. What do you mean by the 1st point? - the gas is still spent. (in fact, all of it is.) I thought that contracts only used gas as needed (processing EVM instructions, storage etc...) and any gas left over is automatically returned to the transaction sender.
    – Alex Darby
    Commented Jun 15, 2016 at 0:41
  • is the gas spend up to gasLimit? Commented Jun 15, 2016 at 5:11
  • @AlexDarby Your thought is correct but for exceptions and throw: ethereum.stackexchange.com/questions/2307/…
    – eth
    Commented Jun 15, 2016 at 6:17
  • 1
    @RolandKofler: Yes. It's as if the transaction used up all the gas and was reverted. Commented Jun 15, 2016 at 14:37

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.