<p>For a transaction that's not considered &quot;yours&quot; by the Bitcoin Core wallet, the only way to learn anything about it is through the optional transaction index.</p>
<p>If you have the transaction index enabled (<code>-txindex</code> on the command line or <code>txindex=1</code> in the configuration file), you can use the <code>getrawtransaction</code> RPC with a txid to find the transaction in the chain. If you add a <code>true</code> after the txid, it'll also report the transaction in decoded format, along with other information such as the number of confirmations. E.g. you'd run:</p>
<pre><code>bitcoin-cli getrawtransaction f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 true
</code></pre>
<p>and get as response:</p>
<pre><code>{
  &quot;in_active_chain&quot;: true,
  &quot;txid&quot;: &quot;f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16&quot;,
  &quot;hash&quot;: &quot;f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16&quot;,
  &quot;version&quot;: 1,
  &quot;size&quot;: 275,
  &quot;vsize&quot;: 275,
  &quot;weight&quot;: 1100,
  &quot;locktime&quot;: 0,
  &quot;vin&quot;: ...,
  &quot;vout&quot;: ...,
  &quot;hex&quot;: &quot;0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000&quot;,
  &quot;blockhash&quot;: &quot;00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee&quot;,
  &quot;confirmations&quot;: 732767,
  &quot;time&quot;: 1231731025,
  &quot;blocktime&quot;: 1231731025
}
</code></pre>
<p>If you already know in which block the transaction was confirmed, you can verify it using the same RPC (even without transaction index) by adding the block hash as parameter:</p>
<pre><code>bitcoin-cli getrawtransaction f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 true 00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee
</code></pre>
<p>These commands can also be issued in the Bitcoin-Qt debug console.</p>

CC BY-SA 4.0
2022-05-18T18:29:49.770Z
Fantastic. Thanks. I enabled `txindex=1` in the configuration file. However, upon running `getrawtransaction [txid] true` I am getting the following error: `No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions. (code -5)`. Any ideas why this could be?
StatsScared
CC BY-SA 4.0
2022-05-19T13:50:13.287Z
Are you sure you downloaded the whole blockchain with txindex=1 ? Because if you've just changed it from 0 to 1, when you will restart Bitcoin Core, it will reindex and download the whole blockchain again.
If not, you have to provide the blockhash to tel bitcoin-cli where to look for.
mbh86
CC BY-SA 4.0
2022-05-16T13:09:59.263Z
2022-05-16T14:59:07.153Z
2022-05-16T14:59:07.153Z
Pieter Wuille
<p>I am interested in figuring out at what height a transaction was mined, but I cannot find the right command to extract this information. Perhaps it's not possible?</p>
<p>My Bitcoin Core was not involved as sender or receiver of the transaction.</p>

CC BY-SA 4.0
2022-05-16T12:51:52.687Z
Is your Bitcoin Core wallet involved in the transaction (i.e., did it send/receive the transaction, or is it sending to an address created by it)?
Pieter Wuille
CC BY-SA 4.0
2022-05-16T12:59:08.530Z
@PieterWuille. It’s neither. The transaction in question was sent from from a centralized exchange to a non-Bitcoin Core wallet.
StatsScared
<bitcoin-core><json-rpc><confirmations><txindex>
Can I use the Bitcoin Core CLI to learn the block height at which a transaction was mined?
StatsScared
# Can I use the Bitcoin Core CLI to learn the block height at which a transaction was mined?

(Asked by: username_0 on 2022-05-16)

I am interested in figuring out at what height a transaction was mined, but I cannot find the right command to extract this information. Perhaps it's not possible?

My Bitcoin Core was not involved as sender or receiver of the transaction.

**Tags:** bitcoin-core, json-rpc, confirmations, txindex

> **Comments:**
> **username_1**: Is your Bitcoin Core wallet involved in the transaction (i.e., did it send/receive the transaction, or is it sending to an address created by it)?  
> **username_0**: @username_1. It’s neither. The transaction in question was sent from from a centralized exchange to a non-Bitcoin Core wallet.  

---

## 1 answers

### Answer by username_1 on 2022-05-16. Score: 3 | Accepted answer

For a transaction that's not considered "yours" by the Bitcoin Core wallet, the only way to learn anything about it is through the optional transaction index.

If you have the transaction index enabled (`-txindex` on the command line or `txindex=1` in the configuration file), you can use the `getrawtransaction` RPC with a txid to find the transaction in the chain. If you add a `true` after the txid, it'll also report the transaction in decoded format, along with other information such as the number of confirmations. E.g. you'd run:

```
bitcoin-cli getrawtransaction f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 true

```

and get as response:

```
{
  "in_active_chain": true,
  "txid": "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
  "hash": "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
  "version": 1,
  "size": 275,
  "vsize": 275,
  "weight": 1100,
  "locktime": 0,
  "vin": ...,
  "vout": ...,
  "hex": "0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000",
  "blockhash": "00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee",
  "confirmations": 732767,
  "time": 1231731025,
  "blocktime": 1231731025
}

```

If you already know in which block the transaction was confirmed, you can verify it using the same RPC (even without transaction index) by adding the block hash as parameter:

```
bitcoin-cli getrawtransaction f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16 true 00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee

```

These commands can also be issued in the Bitcoin-Qt debug console.

> **Comments:**
> **username_0**: Fantastic. Thanks. I enabled `txindex=1` in the configuration file. However, upon running `getrawtransaction [txid] true` I am getting the following error: `No such mempool transaction. Use -txindex or provide a block hash to enable blockchain transaction queries. Use gettransaction for wallet transactions. (code -5)`. Any ideas why this could be?  
> **username_2**: Are you sure you downloaded the whole blockchain with txindex=1 ? Because if you've just changed it from 0 to 1, when you will restart Bitcoin Core, it will reindex and download the whole blockchain again. If not, you have to provide the blockhash to tel bitcoin-cli where to look for.  

---

