How do I find out what block a transaction is in?

3

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?

user3601780

Posted 2015-06-10T18:53:44.167

Reputation: 33

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 2015-06-10T19:35:06.563

If you set txindex=1 in the conf then it will index all transactions.user3601780 2015-06-11T20:24:27.430

Answers

4

./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 }

Jonas Schnelli

Posted 2015-06-10T18:53:44.167

Reputation: 5 465

How does this work though? Does bitcoin client build an index of all transactions in the block chain?Andrew Savinykh 2015-12-02T20:34:56.473

Yes. This only works for "all transactions" when -txindex is enabled.Jonas Schnelli 2015-12-14T12:22:29.803