## How can I find the coinbase transactions where the bitcoins involved in a transaction were created?

3

I am exploring a transaction and if would like to know when was the money created, I guess I would end up with a lot of coinable transactions. For a certain transaction I could explore the previous transactions successively until I found the coinbases. But I imagine this would be a very laborious job that could take a lot of resources. Just like blockchains.info trees ( https://blockchain.info/tree/59587897) but expanding the tree till the coinbase transactions

In the other hand I guess nodes when verifying a transaction do something very similar, don’t they? How could I create this list of coinable transactions that original the bitcoins involved in a particular transaction?

2

If you have running bitcoin core, you can use JSON RPC and any programming language you want.

1. getrawtransaction <txid>
2. decoderawtransaction <hex>

Second call will return all inputs of transaction. If transaction has previous tx equal to 32 zeroes, it is coinbase transaction. You should recursively cycle through all parent transactions.

API calls list

1That will probably take you hours or days to find all coinbases. – Pieter Wuille – 2017-01-25T16:09:34.187

I already was exploring this idea but is slow as @pieter-wuille suggested I am exploring 20 inputs/s. It would take ages. Isn't any faster alternative? – muimota – 2017-01-25T19:23:13.977

1

Nodes when verifying a transaction do something very similar, don’t they?

That is true, but there is one difference. When full nodes initialize, they go through each and every transaction in the blockchain since the genesis block. As they go through the transaction, they build up a set of all unspent transaction outputs (UTXOs). When a new transaction arrives,the inputs are checked against this UTXO set to ensure they have not been spent in the past. When verified, the inputs are removed and the new outputs are added to the UTXO set. So, the UTXO set does not contain a tree going back to the coinbase transaction, but rather only transaction outputs that have not yet been spent.

How could I create this list of coinable transactions that original the bitcoins involved in a particular transaction?

The coinbase transaction is the first transaction in any block. You could use JSON-RPC getblockhash and getblock to get block data. After that you can fetch the txid of the first transaction of every block. Then, you could use the getrawtransaction and decoderawtransaction calls to decode every coinbase transaction and get the data that you need like the block rewards, addresses that it paid to etc.

-1

Coinbase transaction is the first transaction of a block.