3

I'm developing a script that processes blk.dat files from bitcoin core. So far, I am able to retrieve the following attributes for transaction inputs:

"vin",
"index",
"sigScript",
"sequence",
"witness"

Is it possible to get the address and the value of the input from the blk.dat files?

In case you need more info or the question is not clear, please let me know.

The Hulk
  • 77
  • 7

1 Answers1

2

Is it possible to get the address and the value of the input from the blk.dat files?

Yes. It is possible. After all, that's effectively what blockchain explorers do.

I would try to do something like the following

  • Use the previous transaction id to look up and obtain the contents of the previous transaction.
  • Use the index to retrieve the specific output of the previous transaction being used as an input in the current transaction
  • Obtain the value from that output.
  • Derive an address from the locking script (AKA ScriptPubKey) of that output.

Potentially useful:

RedGrittyBrick
  • 24,039
  • 3
  • 23
  • 47
  • I do not really have a full answer, but maybe to add to RGB's: Yes, but a transaction itself only identifies the outpoint of the UTXO it spends in an input. So, you need to find that previous transaction to read the output data there. It would probably help to run the full node with `txindex` to that end. – Murch Dec 02 '22 at 15:55
  • It's a bit of a mystery to me how I can look up a specific transaction from raw data. I can use the txid of the input with a web api and get the transaction contents but this has proved to be a bit slow due to exceptions raised from too many requests to the server. – The Hulk Dec 06 '22 at 08:50
  • 1
    The `txindex` configuration option will cause Bitcoin Core to maintain an index of txids. You can use its RPC API - maybe [`gettxout`](https://developer.bitcoin.org/reference/rpc/gettxout.html) (which I guess would work for UTXOs without txindex) – RedGrittyBrick Dec 06 '22 at 10:57