<p>Addresses aren't mentioned in the blockchain. But you can calculate them based on the transaction scripts. In order to do this, you need to calculate the address from the <a href="https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout" rel="nofollow noreferrer"><code>scriptPubkey</code></a> of each transaction. To calculate the address you have to:</p>

<ol>
<li>Determine whether it is a <a href="https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout" rel="nofollow noreferrer"><code>P2PKH</code></a> or <a href="https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout" rel="nofollow noreferrer"><code>P2SH</code></a>, so you know what prefix to use: <a href="https://en.bitcoin.it/wiki/List_of_address_prefixes" rel="nofollow noreferrer">List of address prefixes</a>.</li>
<li>Calculate the <code>BASE58CHECK(HASH160(&lt;prefix&gt;&lt;scriptPubKey&gt;))</code></li>
</ol>

CC BY-SA 4.0
2018-08-20T14:20:20.593Z
2018-08-20T14:20:20.593Z
JBaczuk
<p>I'd like to parse the blockchain in order to produce a list of all addresses that are mentioned in the blockchain.</p>

<p>I'd like to do this with a program, language agnostic.</p>

CC BY-SA 4.0
2018-08-19T18:32:43.340Z
Just use a tool: https://github.com/mrqc/bitcoin-blk-file-reader and modify the code as you like.
Erhard Dinhobl
CC BY-SA 4.0
2019-01-07T12:08:08.527Z
Several Bitcoin implementations index by address already. See libbitcoin-server, which allows you to query for all tx spending to/from an address. Unless you are interested in doing this yourself :)
James C.
<blockchain><address>
How can you get a list of all addresses mentioned in the blockchain?
user1973385
# How can you get a list of all addresses mentioned in the blockchain?

(Asked by: username_0 on 2018-08-19)

I'd like to parse the blockchain in order to produce a list of all addresses that are mentioned in the blockchain.

I'd like to do this with a program, language agnostic.

**Tags:** blockchain, address

> **Comments:**
> **username_1**: Just use a tool: https://github.com/mrqc/bitcoin-blk-file-reader and modify the code as you like.  
> **username_2**: Several Bitcoin implementations index by address already. See libbitcoin-server, which allows you to query for all tx spending to/from an address. Unless you are interested in doing this yourself :)  

---

## 1 answers

### Answer by username_3 on 2018-08-20. Score: 1

Addresses aren't mentioned in the blockchain. But you can calculate them based on the transaction scripts. In order to do this, you need to calculate the address from the [`scriptPubkey`](https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout) of each transaction. To calculate the address you have to:

1. Determine whether it is a [`P2PKH`](https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout) or [`P2SH`](https://en.bitcoin.it/wiki/Transaction#General_format_.28inside_a_block.29_of_each_output_of_a_transaction_-_Txout), so you know what prefix to use: [List of address prefixes](https://en.bitcoin.it/wiki/List_of_address_prefixes).
2. Calculate the `BASE58CHECK(HASH160(<prefix><scriptPubKey>))`


---

