1

I am attempting to call transactions that execute methods on a contract in order to collect specific data. I am currently using web3.eth.getTransaction(hash) in order to view the transaction information.

I correctly receive a return value, however, I cannot see any data that helps me determine if this was a failed transaction. I want to be able to detect failed transactions so that I exclude failed transactions from my data.

When I called:

web3.eth.getTransaction('0xb818a71e2d8bc6b661f463fbf96c91ecbf60610042b39da7e8806b2e0b5c2575', (e,r) => {tx = r})

I received this return value:

{ blockHash:
   '0xfcce6583cfede31bd59b53ac4b562b391a0c1f1b8539f4961ded1418be50d241',
  blockNumber: 2856676,
  from: '0x852bCCfd7446D236C353C804881048124F2a32B1',
  gas: 21000,
  gasPrice: '25000000000',
  hash:
   '0xb818a71e2d8bc6b661f463fbf96c91ecbf60610042b39da7e8806b2e0b5c2575',
  input: '0x',
  nonce: 3,
  r:
   '0x60b4dcc69230b1a69775ad20d0c105dfbfc52c953031deb1dbeab8a726ece2d6',
  s:
   '0x2cbd567f6fcac3c5284f8b531e302ee8f037a695029164f1bc68bf1218e8361',
  to: '0x0F0F0fc0530007361933EaB5DB97d09aCDD6C1c8',
  transactionIndex: 0,
  v: '0x2d',
  value: '32000000000000000000' }

Is there anything in there that can tell me if the tx failed?

1

You can get the status with web3.eth.getTransactionReceipt().

Running that command with your tx hash will produce the following:

web3.eth.getTransactionReceipt('0xb818a71e2d8bc6b661f463fbf96c91ecbf60610042b39da7e8806b2e0b5c2575')

> { blockHash:
   '0xfcce6583cfede31bd59b53ac4b562b391a0c1f1b8539f4961ded1418be50d241',
  blockNumber: 2856676,
  contractAddress: null,
  cumulativeGasUsed: 21000,
  from: '0x852bccfd7446d236c353c804881048124f2a32b1',
  gasUsed: 21000,
  logs: [],
  logsBloom:
   '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  status: false,
  to: '0x0f0f0fc0530007361933eab5db97d09acdd6c1c8',
  transactionHash:
   '0xb818a71e2d8bc6b661f463fbf96c91ecbf60610042b39da7e8806b2e0b5c2575',
  transactionIndex: 0 }

You can see that the status flag is set to false, which indicates that the transaction failed.

As a note, this was added in the Byzantium hard fork.

| improve this answer | |

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.