I'm using bitcoin-cli. I have a TXID, and I'd like to find which block it is in. Either the block hash or block count would be fine. What's the best way to do this?

I've tried using gettransaction < txid> and going from there, but I get this error:

error: {"code":-5,"message":"Invalid or non-wallet transaction id"}

1 Answer 1


Bitcoin Core doesn't maintain an index of transactions which are not relevant to you by default to save space and processing time.

You need to run your node with txindex=1 in the configuration in order to create one, and changing the option on an existing node requires you do do a bitcoind -reindex. A reindex is equivalent to doing a full network sync again but will use all of the block files you already have on disk for the process. When this is complete you will be able to look up arbitrary TXID using the getrawtransaction RPC (gettransaction only applies to transactions in your wallet).

$ bitcoin-cli getrawtransaction 74cffe12b2d58ac2e2bc13de5519428639267e2faffb85bbbfec60d8be7cdb50 1

  "blockhash": "0000000000000000027d382ef7c586e0e97f623e685c9f927e78865420f72b5f",
  "confirmations": 2,
  "time": 1444654960,
  "blocktime": 1444654960
  • Note that this extra index also takes up some extra disk space.
    – Jannes
    Oct 13, 2015 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.