2

I am writing a program that reads Bitcoin transactions from .blk files and performs some analysis on them. I would like to get the transaction destination addresses (like in some transaction explorers: link.

Raw transaction data looks like this and I don't see any address fields anywhere.

How is it possible to calculate it? Is there a (preferably C/C++) program that already does that? Or are there any details on how to implement this?

Best regards and thanks for all answers in advance! :)

1 Answer 1

3

Raw transaction data looks like this and I don't see any address fields anywhere.

That's because transactions don't directly involve addresses. An address is an abstraction of a Bitcoin-script used in a transaction. An address is a way for a payee to externally communicate to a payer enough information for the payer to construct an output entry for a new transaction.

are there any details on how to implement this?

See for example https://learnmeabitcoin.com/technical/p2pkh

Calculating address of P2PKH script

So for a pay-to-public-key-hash (P2PKH) address you:

  • Calculate a Hash160 (SHA256 + RIPEMD160) of the public key
  • Prefix that hash with 0x00
  • Suffix with a checksum (first four bytes of a SHA256 hash of other data)
  • Encode in Base58

You'd need to separately handle address formation for every standard type of Bitcoin-script. Some don't have a standard way to derive an address.

1
  • Thank you for your answer! Does any of you know a library (preferably in C++) that would be able to calculate address from given data?
    – zigak
    Sep 16, 2021 at 12:30

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.