bitcoind: How to find the block from a TXID? 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 &lt; txid> and going from there, but I get this error:

error: {"code":-5,"message":"Invalid or non-wallet transaction id"}
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
}