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

<p>You need to run your node with <code>txindex=1</code> in the configuration in order to create one, and changing the option on an existing node requires you do do a <code>bitcoind -reindex</code>. 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 <code>getrawtransaction</code> RPC (<code>gettransaction</code> only applies to transactions in your wallet). </p>

<pre><code>$ bitcoin-cli getrawtransaction 74cffe12b2d58ac2e2bc13de5519428639267e2faffb85bbbfec60d8be7cdb50 1

{
  .....
  "blockhash": "0000000000000000027d382ef7c586e0e97f623e685c9f927e78865420f72b5f",
  "confirmations": 2,
  "time": 1444654960,
  "blocktime": 1444654960
}
</code></pre>

CC BY-SA 3.0
2015-10-13T10:18:47.370Z
Note that this extra index also takes up some extra disk space.
Jannes
CC BY-SA 3.0
2015-10-13T10:07:20.323Z
2015-10-13T14:35:45.507Z
2015-10-13T14:35:45.507Z
Claris
<p>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?</p>

<p>I've tried using <em>gettransaction &lt; txid></em> and going from there, but I get this error:</p>

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

<bitcoind>
bitcoind: How to find the block from a TXID?
inersha
# bitcoind: How to find the block from a TXID?

(Asked by: username_0 on 2015-10-13)

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"}

```

**Tags:** bitcoind


---

## 1 answers

### Answer by username_1 on 2015-10-13. Score: 8 | Accepted answer

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
}

```

> **Comments:**
> **username_2**: Note that this extra index also takes up some extra disk space.  

---

