[Ethereum] How to query local Ethereum blockchain for a specified transaction

private-blockchainquerytransactions

I want to find specified transaction.
How can I query my local Ethereum blockchain from the console?

Best Answer

Find Transaction By Transaction Hash

Ideally you would have saved the transaction hash, and then you can query for the transaction using this transaction hash. Here is an example:

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1.23456, "ether")})
"0x4a950bc3651c991aa2ff50fc49601e69960f1f75823df3d4a5dfc7d3c5e3c190"

Use eth.getTransaction(txHash) to get the transaction details. The transaction has not been mined into a block yet:

> eth.getTransaction("0x4a950bc3651c991aa2ff50fc49601e69960f1f75823df3d4a5dfc7d3c5e3c190")
{
  blockHash: null,
  blockNumber: null,
  from: "0xa485ab3ad17cd9aca6fd5343a53a513685c7e0ed",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0x4a950bc3651c991aa2ff50fc49601e69960f1f75823df3d4a5dfc7d3c5e3c190",
  input: "0x",
  nonce: 201,
  to: "0xcf358622d70f62f212aef64e7e26e4746dc84eb3",
  transactionIndex: null,
  value: 1234560000000000000
}

The transaction has just been mined:

I0430 21:20:39.493822   14719 worker.go:569] commit new work on block 10543 with 1 txs & 0 uncles. Took 1.257998ms

> eth.getTransaction("0x4a950bc3651c991aa2ff50fc49601e69960f1f75823df3d4a5dfc7d3c5e3c190")
{
  blockHash: "0xeb71b38f6301c570a46d864a0159ddd2b352dec8409a64f210778d8826e4fda0",
  blockNumber: 10543,
  from: "0xa485ab3ad17cd9aca6fd5343a53a513685c7e0ed",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0x4a950bc3651c991aa2ff50fc49601e69960f1f75823df3d4a5dfc7d3c5e3c190",
  input: "0x",
  nonce: 201,
  to: "0xcf358622d70f62f212aef64e7e26e4746dc84eb3",
  transactionIndex: 0,
  value: 1234560000000000000
}


Find Transaction Using A Script To Search For Transaction To/From Account

Otherwise see the answer Script To Find Transactions To/From An Account to the question Common useful JavaScript snippets for geth for a scripts to search the blockchain for your transaction.

Related Topic