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.

1 Answer 1

3

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:

3
  • 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 2, 2022 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.
    – Andreas
    Dec 6, 2022 at 8:50
  • 1
    The txindex configuration option will cause Bitcoin Core to maintain an index of txids. You can use its RPC API - maybe gettxout (which I guess would work for UTXOs without txindex) Dec 6, 2022 at 10:57

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.