1

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?

2
  • In what way specifically do you mean? Like through an API or something. You obviously don't mean manually, right? The block for this transaction is listed at the bottom.
    – frеdsbend
    Jun 6, 2014 at 5:27
  • 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
    Jun 6, 2014 at 7:06

1 Answer 1

2

According to the Wiki, 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.

7
  • 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
    Jun 6, 2014 at 8:10
  • @slouis don't forget to vote and select if this answer works for you.
    – frеdsbend
    Jun 6, 2014 at 8:24
  • @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
    Jun 6, 2014 at 9:11
  • Not if I am saving the whole transaction. But I got the idea. Thanks!
    – slouis
    Jun 6, 2014 at 10:17
  • I'm afraid that I don't understand what you mean by that.
    – Jori
    Jun 6, 2014 at 10:34

Your Answer

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

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