0

I am writing a program that reads Bitcoin transactions from .blk files and performs some analysis on them. I would like to get transaction destination address (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

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 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.