4

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

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
gkucmierz
  • 773
  • 2
  • 8
  • 15

2 Answers2

7

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.

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
0

to get details of any transaction you need a transaction hash

var tx = {from: eth.coinbase, to:eth.accounts[1], value: web3.toWei(10, "ether")}
> personal.sendTransaction(tx,"your_passphrase")

after executing this you will get the transaction hash

"0x575021e07c382ff4af7deaa884bc1e32c21a1e1a537530495460fb5f6bb295a6"

Using this transaction hash you will get the transaction transaction details can be of three types

  1. Transaction Receipt

  2. Transaction

  3. Block

1.To get transaction Receipt

> eth.getTransactionReceipt("0x575021e07c382ff4af7deaa884bc1e32c21a1e1a537530495460fb5f6bb295a6");
{
  blockHash: "0x1e19da77340a213e740b586d946babf8e71e04c96f688a563f329e7c37e7a383",
  blockNumber: 73003,
  contractAddress: null,
  cumulativeGasUsed: 21000,
  from: "0xf0606aab9ed3f89a4167b43ce4eed4ff8f4cc195",
  gasUsed: 21000,
  logs: [],
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000",
  root: "0x32668b7edc01f7fcd555dec72ee316fe0233ba61a09216bdd016d981ebd9b165",
  to: "0x431bd477b572bb085d55a6f81f49f682a8ffcfbc",
  transactionHash: "0x575021e07c382ff4af7deaa884bc1e32c21a1e1a537530495460fb5f6bb295a6",
  transactionIndex: 0
}
  1. To get Transaction

eth.getTransaction("0x575021e07c382ff4af7deaa884bc1e32c21a1e1a537530495460fb5f6bb295a6")

{
  blockHash: "0x1e19da77340a213e740b586d946babf8e71e04c96f688a563f329e7c37e7a383",
  blockNumber: 73003,
  from: "0xf0606aab9ed3f89a4167b43ce4eed4ff8f4cc195",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0x575021e07c382ff4af7deaa884bc1e32c21a1e1a537530495460fb5f6bb295a6",
  input: "0x",
  nonce: 371,
  r: "0x89012f754609ddd92af62d886c384b89f3b01d56c3119f54ee21ffa4bbd6c6f3",
  s: "0x5d71aa0300f36dfc44dff4711b04a5687e905561cf0a1fcf254057141291dc86",
  to: "0x431bd477b572bb085d55a6f81f49f682a8ffcfbc",
  transactionIndex: 0,
  v: "0x1344248",
  value: 10000000000000000000
}
  1. To get the Block which contains this transaction you need to use block number which will be found in above two details of transaction

eth.getBlock(17003)

{
  difficulty: 3187411,
  extraData: "0xd783010600846765746887676f312e382e31856c696e7578",
  gasLimit: 4712388,
  gasUsed: 56044,
  hash: "0xe4920d566712ddadef12a06758616c07337eb608529791fb65e6bdd1a84899ee",
  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000",
  miner: "0xf0606aab9ed3f89a4167b43ce4eed4ff8f4cc195",
  mixHash: "0x1ed2e2f5f8c92d0571ef1cd1a7311a5829733d6ad394c64b366cc528fcc6b4ce",
  nonce: "0x30eef6803d21695c",
  number: 17003,
  parentHash: "0x0cfb767909ad8a36d75a35e83473b51b57aea33dd7a1ff6d32ca1e893c2094d3",
  receiptsRoot: "0x0447badab863852e4414f5dc453ea3c8959472478d1627948e93b4b39e6f7890",
  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  size: 716,
  stateRoot: "0xebeecad538dd160db0038cd877b7ab5cdd79328ceb9543e34d8afa6be964f890",
  timestamp: 1494401773,
  totalDifficulty: 36988653229,
  transactions: ["0xb25c31b1dbbbbdc445c2114f37c34b0b3cd87759b24f019026bf7a0832395065"],
  transactionsRoot: "0x6ae8386d4642ec302e0943b58e9e6cc4a03af4bbb288a064cc63d2b00ef2433a",
  uncles: []
}

you can use all 3 of them from javascript by using web3

  1. web3.eth.getTransactionReceipt("transaction Hash")
  2. Web3.eth.getTransaction(transaction Hash)
  3. web3,eth.getBlock(Block number/block hash)
SwapnilKumbhar
  • 763
  • 1
  • 11
  • 31