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! :)

Murch
  • 75,206
  • 34
  • 186
  • 622
zigak
  • 21
  • 2

1 Answers1

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.

RedGrittyBrick
  • 26,841
  • 3
  • 25
  • 51
  • 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 '21 at 12:30