21

Apparently when sending transactions from an Account instead of a Wallet, the gas spent is small (21K), and not enough to send ether to a Contract Wallet (out of gas, so to speak).

When this happens, the transaction shouldn't go through (or be cancelled, as it says here), however it seems to still be recorded in the blockchain, why? Example.

Doesn't etherscan.io provide any clue about if the transaction ended up being valid or not? In this case it should be marked as CANCELLED/INVALID in that URL, as far as I understand.

2
  • ok thanks, BTW is there a way to know this status via RPC? should I open a new question about this or is there already one?
    – knocte
    Feb 9, 2016 at 6:03
  • 2
    It might be similar to this question ethereum.stackexchange.com/q/1181/42 ? RPC eth_getTransactionReceipt and checking the gas used is a good way to find out. Sorry I won't flag if you open a new question.
    – eth
    Feb 9, 2016 at 6:07

5 Answers 5

15

Using etherscan blockchain explorer

In etherscan, look for the TxReceipt Status which will have Fail in red, or Success in green.

Example of a failure: https://ropsten.etherscan.io/tx/0x67a5f6442f49a5da6ff8682250a8eef899d9dc0c5adf20b683709433902b5956

Using the receipt

eth.getTransactionReceipt(transactionHash) will return a status field that has a value of 0 when a transaction has failed and 1 when the transaction has succeeded.

Here's an example showing the status field:

{ blockHash: '0xb1fcff633029ee18ab6482b58ff8b6e95dd7c82a954c852157152a7a6d32785e',
  blockNumber: 4370000,
  contractAddress: null,
  cumulativeGasUsed: 21000,
  gasUsed: 21000,
  logs: [],
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  root: null,
  status: 1, // **** HERE IS THE STATUS FIELD *****
  transactionHash: '0x1421a887a02301ae127bf2cd4c006116053c9dc4a255e69ea403a2d77c346cf5',
  transactionIndex: 0 }

More details here.


Historical

To see if a transaction ran out of gas, you can input the transaction (hash) in https://live.ether.camp and then click on "VM Trace". (For the testnet Morden, use https://morden.ether.camp)

Or plug in the transactionHash in this url:

https://live.ether.camp/transaction/<transactionHash>/vmtrace#0

For the transaction mentioned in the question, 022f440fa96eb469363804d7b6c52321d4f409fa76578cdbdc5f04ff494b1321

here is the output https://live.ether.camp/transaction/022f440fa96eb469363804d7b6c52321d4f409fa76578cdbdc5f04ff494b1321/vmtrace#0

enter image description here

This transaction was out of gas immediately. Some transactions may run out of gas after doing some computations, and clicking on the Operations will show each step being performed and when the out of gas happens.

2
  • How is it possible status to be failed, but contract still be deployed? Should not transaction be reverted in case of failure?
    – k06a
    Oct 20, 2017 at 8:59
  • @k06a Think that should be a new question and include your transaction hash so the community can help debug.
    – eth
    Nov 2, 2017 at 9:08
5

So you transaction did went trough in the sense that it was broadcasted to the network and included in a block. However - as you have already suggested the gas you payed was not sufficient for this transaction. To prevent corrupted states in this case all the effects a transaction has will be rolled back. The only effect is that costs for the gas (in Ether) will be reduced from your account and credited to the miner who included the transaction in a block.

On https://etherscan.io/ there is no clear indication whether or not the gas was sufficient. However - the site states the "Cumulative Gas Used" and if it is equal to the "Gas" (the gas limit you set) than this is a very strong indicator that the transaction ran out of Gas. (In theory it could have indeed used that exact amount but this is very unlikely)

http://frontier.ether.camp/ is a more sophisticated block explorer and here you can see whether or not the "out of gas" exception was thrown.

1
  • 2
    When it is back up, I think the link is actually live.ether.camp
    – eth
    Feb 9, 2016 at 5:59
5

Just to clarify to the above question, Etherscan now does show if there is an error during the contract execution. A red remark indicates an error and a green remark indicates a confirmed contract invocation.

Most of the exceptions for failed contracts are due to "out of gas". And as PaulS + mKoeppelmann has stated above, one way to determine if you have run out of gas is to match the gasSent == gasUsed. However, solely using this method would be inaccurate as there can be other exceptions that the contract first hits before it runs out of gas

5
  • cool, but I'm still worried about considering transactions out of gas when exactly gasSent == gasUsed, in case the operation required that amount of gas (and not more) to be complete; it may be a rare case, but it could happen
    – knocte
    Feb 29, 2016 at 8:14
  • For all purposes, you should. As I stated above its not definite though most likely as there are other exceptions and its always possible to provide just enough gas ..
    – mtbitcoin
    Feb 29, 2016 at 8:54
  • so then you're adding the red warning even in the cases when it could be just enough gas?
    – knocte
    Feb 29, 2016 at 9:29
  • 1
    That is one of the of the criterias that I am looking at but not the sole one, nonetheless hence the question mark "?". The only way to be 100% sure is to do a vmtrace (ethercamp) or use the debug.transaction that will be released in the future versions of geth (patch done by ppratscher). This will allow you to replay then entire transaction and trace each step the VM took. Once this become widely available I expect most blockexplorers to use this updated information. It will only get better with time :-)
    – mtbitcoin
    Feb 29, 2016 at 13:10
  • There are three cases when gasSent == gasUsed. (1) all gas was used up and therefore the transaction ran out of gas; (2) there was a 'throw' in which case the all gas gets gobbled up; and (3) the execution succeeds, but the exact amount of gas provided was used up. Transaction types (1) and (2) do not succeed. Transaction type (3) does. Case (3) is the reason why gasSent == gasUsed is not sufficient to tell if the gas ran out and the reason why you must check the trace to be sure. Nov 16, 2016 at 3:21
2

The transaction itself is valid and so it's in the blockchain and picked up by all block explorers. But because it did not specify enough gas the wallet contract code is reverted and so no ether transfer takes place. The insufficient gas specified will still be consumed.

The https://live.ether.camp/ block explorer will indicate that the transaction was cancelled and if you examine the vmtrace view you will see that it ran out of gas.

2

If you want to determine how you've run out of gas programmatically, instead of after the fact debugging, see:

How do I know when I've run out of gas programmatically?

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.