I'm trying to do research on the age of transaction outputs at the time they are spent. I'm running bitcoind on my computer. I have transactions indexed with txindex=1. I want to take a given TXIN and get the block of the TXOUT it spends so I can calculate the age.

How do I get the block a given transaction is included in?

  • as far as i know bitcoind only stores information about addresses in your wallet. it does not create an index for every single address. there are blockchain explorers that do that however, such as Insight by BitPay. – Luca Matteis Jun 10 '15 at 19:35
  • If you set txindex=1 in the conf then it will index all transactions. – user3601780 Jun 11 '15 at 20:24

./src/bitcoin-cli getrawtransaction 4ef653dc90aa25e1a0cc8a45f0484524010e5cc77b8159df6916466c07036482 1 (mind the 1 at the end which means you wish verbose output)

... "blockhash" : "000000000000000009e865d07f75341a5f3dc15f0e149055a241eedd552c3b88", "confirmations" : 1, "time" : 1433965052, "blocktime" : 1433965052 }

  • How does this work though? Does bitcoin client build an index of all transactions in the block chain? – Andrew Savinykh Dec 2 '15 at 20:34
  • Yes. This only works for "all transactions" when -txindex is enabled. – Jonas Schnelli Dec 14 '15 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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