<blockquote>
<p><strong>Raw transaction data looks like this and I don't see any address fields anywhere.</strong></p>
</blockquote>
<p>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.</p>
<blockquote>
<p><strong>are there any details on how to implement this?</strong></p>
</blockquote>
<p>See for example <a href="https://learnmeabitcoin.com/technical/p2pkh" rel="nofollow noreferrer">https://learnmeabitcoin.com/technical/p2pkh</a></p>
<p><a href="https://i.sstatic.net/9xaph.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9xaph.png" alt="Calculating address of P2PKH script" /></a></p>
<p>So for a pay-to-public-key-hash (P2PKH) address you:</p>
<ul>
<li>Calculate a Hash160 (SHA256 + RIPEMD160) of the public key</li>
<li>Prefix that hash with 0x00</li>
<li>Suffix with a checksum (first four bytes of a SHA256 hash of other data)</li>
<li>Encode in Base58</li>
</ul>
<p>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.</p>

CC BY-SA 4.0
2021-09-16T12:30:17.593Z
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
CC BY-SA 4.0
2021-08-05T11:36:04.310Z
2021-08-05T16:39:42.273Z
2021-08-05T16:39:42.273Z
RedGrittyBrick
<p>I am writing a program that reads Bitcoin transactions from <code>.blk</code> files and performs some analysis on them. I would like to get the transaction destination addresses (like in some transaction explorers: <a href="https://blockchair.com/bitcoin/transaction/2221d86b44b270bfee9f83a41bee4153e330817118e0346e2d101227c54b6e05" rel="nofollow noreferrer">link</a>.</p>
<p>Raw transaction data looks like <a href="https://learnmeabitcoin.com/technical/transaction-data" rel="nofollow noreferrer">this</a> and I don't see any address fields anywhere.</p>
<p>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?</p>
<p>Best regards and thanks for all answers in advance! :)</p>

<transactions><address><raw-transaction><output><serialization>
How can I get the destination address from raw transaction data?
zigak
# How can I get the destination address from raw transaction data?

(Asked by: username_0 on 2021-08-05)

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](https://blockchair.com/bitcoin/transaction/2221d86b44b270bfee9f83a41bee4153e330817118e0346e2d101227c54b6e05).

Raw transaction data looks like [this](https://learnmeabitcoin.com/technical/transaction-data) 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! :)

**Tags:** transactions, address, raw-transaction, output, serialization


---

## 1 answers

### Answer by username_1 on 2021-08-05. Score: 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](https://i.sstatic.net/9xaph.png)](https://i.sstatic.net/9xaph.png)

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.

> **Comments:**
> **username_0**: 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?  

---

