<p>You can't get a database of <em>all</em> such public keys, but you can get some of them.</p>

<p>An address, as you know, is a hash of a public key.  When somebody sends coins to an address, you can think of the associated public key as having a positive balance, but nobody else necessarily knows what the public key actually is.  (You can't compute the public key directly from the address, because hash functions are effectively one way.)</p>

<p>However, in order to spend the coins from that address, the spending transaction has to reveal the public key (so that the spending transaction's signature can be verified).  So what you need to look for are addresses with a positive balance that have also had some coins spent.  I am not aware of any simple way to do this short of making an index of all transactions.  It is possible you could rig up a way to produce such a list by querying a fully-synced bitcoind using <code>-txindex</code> (so that all transactions are indexed), but it seems likely to be inefficient.</p>

<p>But as a randomly chosen example, consider the address <a href="https://blockchain.info/address/1Q6NNpHM1pyh6kEqzinBhEgsRc3nmpTGLm">1Q6NNpHM1pyh6kEqzinBhEgsRc3nmpTGLm</a>.  It is associated with some public key which has a balance of BTC 259.7299, but since (as of this writing) no coins have been spent from that address, nobody except the owner of the address knows what the public key is.  So your database will necessarily be incomplete; probably <em>very</em> incomplete.  </p>

<p>In particular, most people use a new address for each of their transactions (including change addresses), in which case the transaction that reveals the public key for an address also spends all its coins (so that the balance is now zero), and that public key will likely never be used again.  This strategy is used partly because certain theoretical cryptographic attacks are easier if the public key is known, and this strategy mitigates the risk from such attacks; it also increases privacy by making it harder to look at patterns of transactions to try to deduce who the address belongs to.</p>

<p>Another case in which you can learn the public key is so-called <a href="http://bitcore.io/guide/script.html#Pay_to_Public_Key_%28p2pk%29">P2PK transactions</a>, where the output script includes the actual destination public key, instead of merely its associated address.  These were common in the past, but these days all standard clients use the P2PKH transaction type, in which only the address is used.</p>

CC BY-SA 3.0
2015-05-08T04:02:51.677Z
Yes, I know that only for a subset of the bitcoin addresses, there is a public key available. My goal is actually to figure out how many there are. My question is more of a implementation question of how I would go about doing this.
Benedikt Bünz
CC BY-SA 3.0
2015-05-08T12:10:37.957Z
Bitcoinlib (https://github.com/petertodd/python-bitcoinlib) will give you the python functionality to scan the blocks and create a database with public keys being reused.   The rest, it seems, is up to you.
linhares
CC BY-SA 3.0
2015-05-07T23:16:30.793Z
2015-05-07T23:27:34.050Z
2015-05-07T23:27:34.050Z
Nate Eldredge
<p>You can use <a href="https://github.com/graymauser/btcposbal2csv" rel="nofollow noreferrer"><code>btcposbal2csv.py</code> script</a> to export the list to CSV.</p>
<blockquote>
<p>To get current addresses with positive balance, let the full node client sync with the network. Stop the bitcoin-core client before running this utility. If you not stop the client, the database might get corrupted.</p>
</blockquote>
<blockquote>
<p>Then run this program with path to chainstate directory (usually <code>$HOME/.bitcoin/chainstate</code>).</p>
</blockquote>
<p>For example, the following will read from <code>~/.bitcoin/chainstate</code>, and write result to <code>~/addresses_with_balance.csv</code>:</p>
<pre><code>./btcposbal2csv.py /home/USER/.bitcoin/chainstate /home/USER/addresses_with_balance.csv
</code></pre>
<p>Notes:</p>
<blockquote>
<ul>
<li>That the output may not be complete as there are some transactions which are not understood by the decoding lib, or that which do not have &quot;address&quot; at all. Such transactions are not processed. Number of them and the total ammount is displayed after the analysis.</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>The output csv file only reflects the chainstate leveldb at your disk. So it will always be few blocks behind the network as you need to stop the bitcoin-core client.</li>
</ul>
</blockquote>
<hr />
<p>You can also download the full list from some websites, e.g.</p>
<ul>
<li><a href="https://bitkeys.work/faq.php" rel="nofollow noreferrer">https://bitkeys.work/faq.php</a> (All Bitcoin Address with Balance in a CSV File).</li>
<li><a href="https://blockchair.com/dumps" rel="nofollow noreferrer">https://blockchair.com/dumps</a> (Database and Full Node Dumps)</li>
</ul>
<hr />
<p>For Ethereum, see: <a href="https://ethereum.stackexchange.com/q/27809/105">How to list ALL Ethereum addresses with a positive balance</a>.</p>

CC BY-SA 4.0
2021-04-20T00:09:02.937Z
Although he explicitly wrote "public keys (not addresses)" in the first sentence.
Nikolaj-K
CC BY-SA 4.0
2020-07-05T00:07:22.550Z
2020-07-05T00:15:37.843Z
2020-07-05T00:15:37.843Z
kenorb
<p>Here is a script based on abe to print all public keys in the blockchain <a href="https://github.com/shivaenigma/bitcoin-abe" rel="nofollow">https://github.com/shivaenigma/bitcoin-abe</a>. You can easily exclude the ones that have zero balance</p>

CC BY-SA 3.0
2016-05-20T17:32:46.673Z
2016-05-20T17:32:46.673Z
dark knight
<p>I want to get a database or otherwise retrieve a set off all bitcoin public keys (not addresses) that have non zero balances. </p>

<p>What would be the easiest way to do that? Is there an API that could do such thing? Do I have to download and prune the whole blockchain? If so how would I do that?</p>

CC BY-SA 3.0
2015-05-07T22:03:56.613Z
What do you mean PK (but not addresses)?  Do you want to exclude RIPEMD(SHA(PK))?  Is that it?
linhares
CC BY-SA 3.0
2015-05-08T04:03:50.920Z
I want to get only the (non-zero-balance) addresses that have a "visible" public key, i.e. from which money has been spend from.
Benedikt Bünz
<blockchain><bitcoind><public-key>
All Bitcoin Public Keys with non-zero balance
Benedikt Bünz
# All Bitcoin Public Keys with non-zero balance

(Asked by: username_0 on 2015-05-07)

I want to get a database or otherwise retrieve a set off all bitcoin public keys (not addresses) that have non zero balances.

What would be the easiest way to do that? Is there an API that could do such thing? Do I have to download and prune the whole blockchain? If so how would I do that?

**Tags:** blockchain, bitcoind, public-key

> **Comments:**
> **username_1**: What do you mean PK (but not addresses)?  Do you want to exclude RIPEMD(SHA(PK))?  Is that it?  
> **username_0**: I want to get only the (non-zero-balance) addresses that have a "visible" public key, i.e. from which money has been spend from.  

---

## 3 answers

### Answer by username_2 on 2015-05-07. Score: 13

You can't get a database of *all* such public keys, but you can get some of them.

An address, as you know, is a hash of a public key. When somebody sends coins to an address, you can think of the associated public key as having a positive balance, but nobody else necessarily knows what the public key actually is. (You can't compute the public key directly from the address, because hash functions are effectively one way.)

However, in order to spend the coins from that address, the spending transaction has to reveal the public key (so that the spending transaction's signature can be verified). So what you need to look for are addresses with a positive balance that have also had some coins spent. I am not aware of any simple way to do this short of making an index of all transactions. It is possible you could rig up a way to produce such a list by querying a fully-synced bitcoind using `-txindex` (so that all transactions are indexed), but it seems likely to be inefficient.

But as a randomly chosen example, consider the address [1Q6NNpHM1pyh6kEqzinBhEgsRc3nmpTGLm](https://blockchain.info/address/1Q6NNpHM1pyh6kEqzinBhEgsRc3nmpTGLm). It is associated with some public key which has a balance of BTC 259.7299, but since (as of this writing) no coins have been spent from that address, nobody except the owner of the address knows what the public key is. So your database will necessarily be incomplete; probably *very* incomplete.

In particular, most people use a new address for each of their transactions (including change addresses), in which case the transaction that reveals the public key for an address also spends all its coins (so that the balance is now zero), and that public key will likely never be used again. This strategy is used partly because certain theoretical cryptographic attacks are easier if the public key is known, and this strategy mitigates the risk from such attacks; it also increases privacy by making it harder to look at patterns of transactions to try to deduce who the address belongs to.

Another case in which you can learn the public key is so-called [P2PK transactions](http://bitcore.io/guide/script.html#Pay_to_Public_Key_%28p2pk%29), where the output script includes the actual destination public key, instead of merely its associated address. These were common in the past, but these days all standard clients use the P2PKH transaction type, in which only the address is used.

> **Comments:**
> **username_0**: Yes, I know that only for a subset of the bitcoin addresses, there is a public key available. My goal is actually to figure out how many there are. My question is more of a implementation question of how I would go about doing this.  
> **username_1**: Bitcoinlib (https://github.com/petertodd/python-bitcoinlib) will give you the python functionality to scan the blocks and create a database with public keys being reused.   The rest, it seems, is up to you.  

---

### Answer by username_3 on 2020-07-05. Score: 1

You can use [`btcposbal2csv.py` script](https://github.com/graymauser/btcposbal2csv) to export the list to CSV.

> To get current addresses with positive balance, let the full node client sync with the network. Stop the bitcoin-core client before running this utility. If you not stop the client, the database might get corrupted.

> Then run this program with path to chainstate directory (usually `$HOME/.bitcoin/chainstate`).

For example, the following will read from `~/.bitcoin/chainstate`, and write result to `~/addresses_with_balance.csv`:

```
./btcposbal2csv.py /home/USER/.bitcoin/chainstate /home/USER/addresses_with_balance.csv

```

Notes:

> * That the output may not be complete as there are some transactions which are not understood by the decoding lib, or that which do not have "address" at all. Such transactions are not processed. Number of them and the total ammount is displayed after the analysis.

> * The output csv file only reflects the chainstate leveldb at your disk. So it will always be few blocks behind the network as you need to stop the bitcoin-core client.

---

You can also download the full list from some websites, e.g.

* <https://bitkeys.work/faq.php> (All Bitcoin Address with Balance in a CSV File).
* <https://blockchair.com/dumps> (Database and Full Node Dumps)

---

For Ethereum, see: [How to list ALL Ethereum addresses with a positive balance](https://ethereum.stackexchange.com/q/27809/105).

> **Comments:**
> **username_4**: Although he explicitly wrote "public keys (not addresses)" in the first sentence.  

---

### Answer by username_5 on 2016-05-20. Score: 0

Here is a script based on abe to print all public keys in the blockchain <https://github.com/shivaenigma/bitcoin-abe>. You can easily exclude the ones that have zero balance


---

