A very elementary question, how do I get a transaction status after firing the transaction? I mean suppose I do a sendTransaction where I transfer some amount of ether from 1 account to other, how can I check the status of the transaction using its hash?
[Ethereum] Transaction Status
byzantiumconfirmationstransactions
Best Answer
Update Oct 21 2017
There are some changes with the Byzantium fork -
getTransactionReceipt(...).status
now returns 0 for a failed transaction and 1 for a successful transaction. EtherScan.io displays this status in the TxReceipt Status: field for transactions. See How do I detect a failed transaction after the Byzantium fork as the REVERT opcode does not consume all gas? for further information.Summary
eth.getTransaction("{txhash}")
andeth.getTransactionReceipt("{txhash}")
will provide you with the details.The
.blockNumber
field will benull
until the transaction is included into a mined block.The examples below show demonstrate some of the ways of detecting the status of a transaction.
Note that there could be an issue detecting whether a transaction has failed due to a thrown error, as the situation can be detected by checking whether
gas = gasUsed
. I've created the question How can the transaction status from a thrown error be detected when gas can be exactly the same as the gasUsed for a successful transaction? to try to resolve this question.And from the findings in the Q&A above, here's a short bit of code to determine the status of your transaction.
The return value above will be
""
if there are no errors, or"Out of gas"
if you run out of gas.Details - Transaction Status
Following are some examples of using
eth.getTransaction(...)
andeth.getTransactionReceipt(...)
to find out the transaction status.Pending Transaction, Not Mined Into Blockchain At Time Of Query
Here's the output when there are no pending transactions
And here's a pending transaction.
.blockNumber = null
.Transaction Mined Successfully, Transaction Status Good
This transaction was executed successfully.
gas(666666) < gasUsed(106824)
.Transaction Mined Successfully, But Contract Execution Failed
Here is an example of a transaction that was successfully mined into the blockchain, but the contract execution failed.
In this case
gas(50878) == gasUsed(50878)
.This occurs because the Smart Contract code called by the transaction detected an error and threw an exception and this consumes ALL gas.
See Why does a Solidity throw consume all gas? for more information about the throwing of errors and gas usage.
And note that there could possibly be the case where a Smart Contract executes without any errors and consumes EXACTLY the same amount of gas as specified with the sent transaction details.
Regular Transaction That Fails, Does Not Get Mined Into The Blockchain
I'm sending more ethers than is available in my account. The error is caught before the transaction is mined into the blockchain.
I'm sending to an invalid address. Again the error is caught before the transaction is mined into the blockchain.
Transaction Mined Successfully, Transaction Status Good, gas=gasUsed
Here's an example where the
gas(21000) == gasUsed(21000)
but the transaction went through successfully.I made this up as the gas required for a regular transaction is 21000 and I specified the
gas=21000
in the transaction details.