Skip to main content
7 of 14
Improvement
BokkyPooBah
  • 40.4k
  • 14
  • 123
  • 193

eth.getTransaction("{txhash}") and eth.getTransactionReceipt("{txhash}") will provide you with the details.

The .blockNumber field will be null until the transaction is included into a mined block.

Following are some examples of using eth.getTransaction(...) and eth.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

// eth.getBlock("pending").transactions[0] = null
> eth.getTransaction(eth.getBlock("pending").transactions[0])
invalid or missing value for params[0]
    at web3.js:3119:20
    at web3.js:6023:15
    at web3.js:4995:36
    at <anonymous>:1:1

And here's a pending transaction

> eth.getTransaction(eth.getBlock("pending").transactions[0])
{
  blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  blockNumber: null,
  from: "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0xdfa60d4e97c242c5222a11b485c051bbdeb133c99baccd34dc33ceae1dc0cd67",
  input: "0x",
  nonce: 181930,
  to: "0x4ac944f4e8ab60f9481bcecd78a9915ed3eb98ba",
  transactionIndex: null,
  value: 1005685497455181600
}


Transaction Mined Successfully, Transaction Status Good

The gas (666666) < gasUsed(106824).

> eth.getTransaction(eth.getBlock("latest").transactions[1])
{
  blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
  blockNumber: 1701040,
  from: "0x81747eb1afd9e2670aa6883ed80973ffcb531e1f",
  gas: 666666,
  gasPrice: 20000000000,
  hash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
  input: "0xf04fd2f3000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000001e0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  nonce: 16,
  to: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
  transactionIndex: 1,
  value: 0
}

> eth.getTransactionReceipt("0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d")
{
  blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
  blockNumber: 1701040,
  contractAddress: null,
  cumulativeGasUsed: 127824,
  from: "0x81747eb1afd9e2670aa6883ed80973ffcb531e1f",
  gasUsed: 106824,
  logs: [{
      address: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
      blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
      blockNumber: 1701040,
      data: "0x00000000000000000000000081747eb1afd9e2670aa6883ed80973ffcb531e1f000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000010b000000000000000000000000000000000000000000000000000000000000025e000000000000000000000000000000000000000000000000000000000047e364",
      logIndex: 0,
      topics: ["0xa8061486280834731cc1ef340255cc5d9880ad748d20cb766f43cb7562ec2c16"],
      transactionHash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
      transactionIndex: 1
  }, {
      address: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
      blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
      blockNumber: 1701040,
      data: "0x000000000000000000000000c3a48462221f4525dd2823853b0d04cf373fe42e00000000000000000000000081747eb1afd9e2670aa6883ed80973ffcb531e1f000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000001c7000000000000000000000000000000000000000000000000000000000000010b000000000000000000000000000000000000000000000000000000000000018400000000000000000000000000000000000000000000000000000000000000c800000000000000000000000000000000000000000000000000000000000000b4000000000000000000000000000000000000000000000000000000000000017700000000000000000000000000000000000000000000000000000000000a03e8",
      logIndex: 1,
      topics: ["0x68a83b20dde5c87dee07cc8d46d46e2fda6f176227f8b1f20dcb93752557df0e"],
      transactionHash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
      transactionIndex: 1
  }, {
      address: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
      blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
      blockNumber: 1701040,
      data: "0x00000000000000000000000081747eb1afd9e2670aa6883ed80973ffcb531e1f000000000000000000000000c3a48462221f4525dd2823853b0d04cf373fe42e000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000001c7000000000000000000000000000000000000000000000000000000000000010b00000000000000000000000000000000000000000000000000000000000001840000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000272000000000000000000000000000000000000000000000000000000000047e558",
      logIndex: 2,
      topics: ["0x61a43b8785d66f3a53c7b8ab814b4c2e4ff15a1a6f8d24d08818e1f426e13906"],
      transactionHash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
      transactionIndex: 1
  }, {
      address: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
      blockHash: "0x425a4d04ac0185863266b0d1b000f579f9675a37c5c6df3bf3cf72e0bc9a94e7",
      blockNumber: 1701040,
      data: "0x00000000000000000000000000000000000000000000000000075fbf48b22000",
      logIndex: 3,
      topics: ["0x8f22ef5ca888de3e246c690a13b066ad49cbf2768b0449441dd6f5bae826a1b1"],
      transactionHash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
      transactionIndex: 1
  }],
  root: "30353b57e937cfc71f0c97d5c98573be1eff440e3db62987bd9cd66b0f3030c4",
  to: "0x2cac6e4b11d6b58f6d3c1c9d5fe8faa89f60e5a2",
  transactionHash: "0x6ef5b459ed945fbabfc3a5ef34fb0087752002c319649ff44c3b2759d13a517d",
  transactionIndex: 1
}    


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 the eth.getTransaction(...).gas (50878) is exactly the same as eth.getTransactionReceipt(...).gasUsed (50878).

This occurs because the Smart Contract code called by the transaction detected an error and threw an exception. See Why does a Solidity throw consume all gas? for more information about the throwing of errors and gas usage.

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.

> eth.getTransaction("0x93f39d4213bc48d9e6adda181ddd468d18163ae894ffc3f1a81d34ea33629f84")
{
  blockHash: "0x43403d50e782e2e4f0e9c94e43ce417b2adaf0e0f9fbb4147c2b288fe3c9dc75",
  blockNumber: 1596065,
  from: "0x46fbf1e97365513bb5bdb894259877e026b7f27d",
  gas: 50878,
  gasPrice: 32210000000,
  hash: "0x93f39d4213bc48d9e6adda181ddd468d18163ae894ffc3f1a81d34ea33629f84",
  input: "0x",
  nonce: 2,
  to: "0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
  transactionIndex: 0,
  value: 211417498879620000000
}
> eth.getTransactionReceipt("0x93f39d4213bc48d9e6adda181ddd468d18163ae894ffc3f1a81d34ea33629f84")
{
  blockHash: "0x43403d50e782e2e4f0e9c94e43ce417b2adaf0e0f9fbb4147c2b288fe3c9dc75",
  blockNumber: 1596065,
  contractAddress: null,
  cumulativeGasUsed: 50878,
  from: "0x46fbf1e97365513bb5bdb894259877e026b7f27d",
  gasUsed: 50878,
  logs: [],
  root: "d6771cfbad8d1f2f7cf413a48e968654ec7626797d3ac0ee6cfac26bba09e352",
  to: "0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
  transactionHash: "0x93f39d4213bc48d9e6adda181ddd468d18163ae894ffc3f1a81d34ea33629f84",
  transactionIndex: 0
}


Regular Transaction That Fails

Here's the balance of my accounts 0 & 1:

> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
10615.64
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
10

(Too bad the balance is on on my dev blockchain).

I'm sending more ethers than is available in my account. In this case gas(90000) > gasUsed(21000). But the transaction failed.

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], amount: web3.toWei(50000, "ether")})
"0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe"
> eth.getTransaction("0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe")
{
  blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
  blockNumber: null,
  from: "0xa7857047907d53a2e494d5f311b4b586dc6a96d2",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe",
  input: "0x",
  nonce: 52,
  to: "0x4d5bbe7fbc80933ffa90ece988a764e41ee6d018",
  transactionIndex: null,
  value: 0
}
> eth.getTransaction("0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe")
{
  blockHash: "0x50868e77e0bbe16a0f34bd2585e12cdac0df1b385e1d86809ccbe3deafd81d0f",
  blockNumber: 2143,
  from: "0xa7857047907d53a2e494d5f311b4b586dc6a96d2",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe",
  input: "0x",
  nonce: 52,
  to: "0x4d5bbe7fbc80933ffa90ece988a764e41ee6d018",
  transactionIndex: 0,
  value: 0
}
> eth.getTransactionReceipt("0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe")
{
  blockHash: "0x50868e77e0bbe16a0f34bd2585e12cdac0df1b385e1d86809ccbe3deafd81d0f",
  blockNumber: 2143,
  contractAddress: null,
  cumulativeGasUsed: 21000,
  from: "0xa7857047907d53a2e494d5f311b4b586dc6a96d2",
  gasUsed: 21000,
  logs: [],
  root: "fbbe3628a53ed1019dec42c439a84d69b2beee7fd99f911cd896739649ff6546",
  to: "0x4d5bbe7fbc80933ffa90ece988a764e41ee6d018",
  transactionHash: "0xc831fa6b166fd8168b7091608d9aee0ee20df8106ec8a4b9a80677bbb08367fe",
  transactionIndex: 0
}
> web3.fromWei(eth.getBalance(eth.accounts[0]), "ether")
10700.64
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
10
BokkyPooBah
  • 40.4k
  • 14
  • 123
  • 193