<p>According to <a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list" rel="nofollow">the Wiki</a>, the <code>gettransaction &lt;txid&gt;</code> call return a JSON object with the following information</p>

<pre><code>"amount" : total amount of the transaction
"confirmations" : number of confirmations of the transaction
"txid" : the transaction ID
"time" : time associated with the transaction[1].
"details" - An array of objects containing:
"account"
"address"
"category"
"amount"
"fee"
</code></pre>

<p>Now just use <code>getblockcount</code> and subtract <code>"confirmations"</code> of the JSON object.</p>

CC BY-SA 3.0
2014-06-06T08:10:07.580Z
Thank you Jori, your approach is probably the best. the problem is that getblockcount is not static (changes over time), hence if I have a bunch of transactions SAVED for more than ~10 min I can't work with your method. But maybe that the best way...Thanks!
slouis
CC BY-SA 3.0
2014-06-06T09:11:00.880Z
@slouis `"confirmations"` isn't static either, but the difference between it and `getblockcount` should be. This would work even if you have your transactions laying around for a year.
Jori
CC BY-SA 3.0
2014-06-06T10:17:08.813Z
Not if I am saving the whole transaction. But I got the idea. Thanks!
slouis
CC BY-SA 3.0
2014-06-06T10:34:07.583Z
I'm afraid that I don't understand what you mean by that.
Jori
CC BY-SA 3.0
2014-06-07T10:42:17.687Z
If I have 100000 transactions (hash), and I want to know which block each transaction is in: I will need to call `"getblockcount"` 100000 times - for every time that I call `get("confirmations")`. Is there a faster way? Furthermore, I might call `getblockcount() - transactionx.get("confirmations")` and in between there will be new block and the 2 counters (confirmation and blockcount) won't be correlated!
slouis
CC BY-SA 3.0
2014-06-07T14:44:12.293Z
`getblockcount() - transactionx.get("confirmations")` will stay the same, because for every extra block there will be an extra confirmation counted. If you need to find the block of so many transactions, I'd recommend scanning the block chain and look for them with `getblock` or so. Then matching those transactions in a simple database to their corresponding blocks.+
Jori
CC BY-SA 3.0
2014-06-06T07:54:26.740Z
2014-06-06T07:54:26.740Z
Jori
<p>For a given transaction, I have its incoming transactions and I am trying to get the number of the block of those transactions. This seems like something that cannot achieve directly.</p>

<p>I am working on python with Json RPC and I want to work directly on the block-chain on my computer and not to use online API such as blockchain.info.</p>

<p>How can I get efficiently the block number of a given transaction?</p>

CC BY-SA 3.0
2014-06-06T07:06:05.170Z
you are right, I should have write that: I am working on python with Json RPC and I want to work directly on the block-chain on my computer and not to use blockchain.info.
slouis
<transactions><json-rpc>
How can I get the block number of given transaction?
slouis
# How can I get the block number of given transaction?

(Asked by: username_0 on 2014-06-05)

For a given transaction, I have its incoming transactions and I am trying to get the number of the block of those transactions. This seems like something that cannot achieve directly.

I am working on python with Json RPC and I want to work directly on the block-chain on my computer and not to use online API such as blockchain.info.

How can I get efficiently the block number of a given transaction?

**Tags:** transactions, json-rpc

> **Comments:**
> **username_0**: you are right, I should have write that: I am working on python with Json RPC and I want to work directly on the block-chain on my computer and not to use blockchain.info.  

---

## 1 answers

### Answer by username_1 on 2014-06-06. Score: 2 | Accepted answer

According to [the Wiki](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list), the `gettransaction <txid>` call return a JSON object with the following information

```
"amount" : total amount of the transaction
"confirmations" : number of confirmations of the transaction
"txid" : the transaction ID
"time" : time associated with the transaction[1].
"details" - An array of objects containing:
"account"
"address"
"category"
"amount"
"fee"

```

Now just use `getblockcount` and subtract `"confirmations"` of the JSON object.

> **Comments:**
> **username_0**: Thank you username_1, your approach is probably the best. the problem is that getblockcount is not static (changes over time), hence if I have a bunch of transactions SAVED for more than ~10 min I can't work with your method. But maybe that the best way...Thanks!  
> **username_1**: @username_0 `"confirmations"` isn't static either, but the difference between it and `getblockcount` should be. This would work even if you have your transactions laying around for a year.  
> **username_0**: Not if I am saving the whole transaction. But I got the idea. Thanks!  
> **username_1**: I'm afraid that I don't understand what you mean by that.  
> **username_0**: If I have 100000 transactions (hash), and I want to know which block each transaction is in: I will need to call `"getblockcount"` 100000 times - for every time that I call `get("confirmations")`. Is there a faster way? Furthermore, I might call `getblockcount() - transactionx.get("confirmations")` and in between there will be new block and the 2 counters (confirmation and blockcount) won't be correlated!  
> **username_1**: `getblockcount() - transactionx.get("confirmations")` will stay the same, because for every extra block there will be an extra confirmation counted. If you need to find the block of so many transactions, I'd recommend scanning the block chain and look for them with `getblock` or so. Then matching those transactions in a simple database to their corresponding blocks.+  

---

