If addr.transfer() fails, does it use a revert- or throw-style exception? In other words, does a failed transfer consume all provided gas?


I believe that it won't consume all of the gas provided.

Whilst as per the documentation it will throw:

<address>.transfer(uint256 amount): send given amount of Wei to Address, throws on failure

Since the "REVERT instruction" EIP it looks like not all of the gas is consumed anymore.

To test this, I created some simple contracts - that can be seen on this EthFiddle.

I deployed the contracts using remix and called the forward function of my Transfer contract and despite the transaction using Remix's default of 3,000,000 gas the actual gas cost was 29,135:

enter image description here

Debugging the transaction, and looking at the stack, I can see that the reasonably recently added REVERT OPCODE was called:

enter image description here

Which I believe accounts for not all of the gas being consumed.


Yes, when address.transfer() fails it throws an exception and reverts any state changes.

Edit to clarify my original answer

As per the documentation, when a .transfer() fails it throws a require-style exception, which will revert any state changes. Require-style exceptions will not consume any gas.

  • 1
    I think that this answer is out of date - see my answer for my research into how changes to the EVM have altered the behavior upon exceptions being thrown. – SteveJaxon Feb 5 '18 at 16:54
  • @SteveJaxon why is this answer out-of-date? As Shaun mentioned, when address.transfer() fails it throws require-style exception. As mentioned in Solidity Docs Error handling. IMO this answer might be incomplete, but not out of date. – Roman Frolov Feb 5 '18 at 17:17
  • The question was "Does ether transfer consume all gas in case of exception?" - you answered "yes, ...". This was correct a year ago, but I don't think that it is true anymore. – SteveJaxon Feb 5 '18 at 17:30
  • I can see how that might be confusing. I was answering this portion of the question: If addr.transfer() fails, does it use a revert- or throw-style exception? The answer is yes, it does revert, as per the docs – Shaun Bevan Feb 5 '18 at 17:32

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.