<p>If you want the total amount of BTC created, you simply need to iterate through the coinbase transactions (first tx in every block) and add up the output. You will then need to subtract the transaction fees for that block to avoid double counting those.</p>

<p>If you want a somewhat accurate money supply, you will need to do the above, and then also subtract any BTC sent to <code>OP_RETURN</code> outputs.</p>

<p>There are also a number of burn addresses and accidental addresses which have had BTC sent to them, but are effectively locking the coins forever as no one has a private key or valid redeem script for them. You can attempt to subtract those, but it is not always possible to identify if an address falls into this category.</p>

<p>Lastly, there are two cases where coinbase transactions had the same txid, which results in burning of one of the outputs:</p>

<pre><code>e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468
d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599
</code></pre>

CC BY-SA 4.0
2019-10-26T22:35:39.723Z
2019-10-26T22:35:39.723Z
Raghav Sood
<p>You can use my <a href="https://github.com/ragestack/blockchain-parser" rel="nofollow noreferrer">parser</a> for all the local BTC raw (real) data.</p>

<p>Then you can find all transactions with </p>

<p><code>"TX from hash = 0000000000000000000000000000000000000000000000000000000000000000"</code></p>

<p>and then </p>

<p><code>"Value = XXXXXXXXXXXXXXXX"</code></p>

<p>(<code>XX</code> - HEX string value of Byte) would be your incremental sum of coin supply.</p>

CC BY-SA 4.0
2019-10-30T13:17:40.047Z
2019-10-30T13:34:04.103Z
2019-10-30T13:34:04.103Z
Denis Leonov
<p>The first transaction in every block is called the coinbase transaction, it is a special transaction that pays the miner their reward. This transaction adheres to different rules than the rest: it has no inputs, but has output(s). </p>

<p>The coinbase transaction outputs are allowed to be equal to or less than the block subsidy (newly minted coins) + all transaction fees in the block. </p>

<p>The block subsidy is a set amount, as defined by the code. The subsidy started at 50 BTC, and that amount is cut in half every  210,000 blocks (25, 12.5, 6.25, etc). </p>

<p>The transaction fees for the block are found by taking the rest of the transactions in the block (ie everything that isn’t the coinbase transaction), and calculating the difference between the inputs and outputs in them. This value (input value - output value) is the implied fee. </p>

<p>Note that there are some odd cases to account for, <a href="https://bitcoin.stackexchange.com/q/38994/63872">this question has a bunch of great info in this regard. </a> in addition to this, there is a non-zero amount of BTC that has been ‘burned’, by being sent to addresses or scripts that are un-spendable, or at least have an extremely small chance of someone actually knowing the private key for them (eg the 1BitcoinEater... address). Depending on how you define ‘coin supply’, it may be worth account for these coins as well. </p>

CC BY-SA 4.0
2019-10-26T22:30:38.567Z
2019-10-27T00:24:37.210Z
2019-10-27T00:24:37.210Z
chytrik
<p>We are working on a small project and imported all block information to mongoDB. Right now we're aiming to calculate the coin supply regarding to the block number.</p>

<p>My plan is to loop through all transactions per block and parse <code>vout</code> and <code>vin</code>. However, I'm not sure how to distinguish mined coins and previously existing coins transferred users. Plus, how to account for transaction fees?
Can I track only <code>"valueOut"</code> and that's all?</p>

<pre><code>{
   "txid":"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
   "version":1,
   "locktime":0,
   "vin":[
      {
         "coinbase":"04ffff001d0104",
         "sequence":4294967295,
         "n":0
      }
   ],
   "vout":[
      {
         "value":"50.00000000",
         "n":0,
         "scriptPubKey":{
            "hex":"410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
            "asm":"0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG",
            "addresses":[
               "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"
            ],
            "type":"pubkeyhash"
         },
         "spentTxId":null,
         "spentIndex":null,
         "spentHeight":null
      }
   ],
   "blockhash":"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
   "blockheight":1,
   "confirmations":601155,
   "time":1231469665,
   "blocktime":1231469665,
   "isCoinBase":true,
   "valueOut":50,
   "size":134
}
</code></pre>

<p>Any help would be appreciated! </p>

CC BY-SA 4.0
2019-10-27T00:23:00.327Z
Hey Prologas, interesting question. I've touched up the body of your question a bit to make it easier to understand. Could you please proofread my changes to verify that I didn't change the essence of your question?
Murch
CC BY-SA 4.0
2019-10-27T08:25:33.537Z
We have really good answers below, and I would like to add a nice hack to them. On Bitcoin-Core, run the command `bitcoin-cli gettxoutsetinfo`. It will give you all the information of the coins outstanding. It calculates that amount by summing all the block subsidies less the amount not claimed by miners, bitcoins sent to `OP_RETURN` outputs, 50 BTC genesis block output that cannot be spent and the two coinbase transactions Raghav Sood mentioned in his answers. It doesn't exclude the Bitcoins sent to `1BitcoinEater...` type addresses as thr is no verifiable way to know if one own the priv key.
Ugam Kamat
CC BY-SA 4.0
2019-10-27T10:49:51.753Z
This works indeed:
```root@b9f3dd35c755:/# bitcoin-cli gettxoutsetinfo
{
  "height": 601237,
  "bestblock": "0000000000000000000f18a401591a0f440668ed1e3d975a64cb3687b796b8c6",
  "transactions": 37206777,
  "txouts": 63615267,
  "bogosize": 4784113473,
  "hash_serialized_2": "88e6d6b2585e83204760db1f383b942dbade97569c7556bdd30b1ad8fcfcdfa9",
  "disk_size": 3833721332,
  "total_amount": 18015292.32182326
}
```
 But minus here if you don't have RPC access and using only public explorer to import data.
pr0logas
<transaction-fees><mining-reward><money-supply>
How to calculate coin supply at each block height from all transactions?
pr0logas
# How to calculate coin supply at each block height from all transactions?

(Asked by: username_0 on 2019-10-26)

We are working on a small project and imported all block information to mongoDB. Right now we're aiming to calculate the coin supply regarding to the block number.

My plan is to loop through all transactions per block and parse `vout` and `vin`. However, I'm not sure how to distinguish mined coins and previously existing coins transferred users. Plus, how to account for transaction fees?
Can I track only `"valueOut"` and that's all?

```
{
   "txid":"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
   "version":1,
   "locktime":0,
   "vin":[
      {
         "coinbase":"04ffff001d0104",
         "sequence":4294967295,
         "n":0
      }
   ],
   "vout":[
      {
         "value":"50.00000000",
         "n":0,
         "scriptPubKey":{
            "hex":"410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
            "asm":"0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG",
            "addresses":[
               "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"
            ],
            "type":"pubkeyhash"
         },
         "spentTxId":null,
         "spentIndex":null,
         "spentHeight":null
      }
   ],
   "blockhash":"00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
   "blockheight":1,
   "confirmations":601155,
   "time":1231469665,
   "blocktime":1231469665,
   "isCoinBase":true,
   "valueOut":50,
   "size":134
}

```

Any help would be appreciated!

**Tags:** transaction-fees, mining-reward, money-supply

> **Comments:**
> **username_1**: Hey Prologas, interesting question. I've touched up the body of your question a bit to make it easier to understand. Could you please proofread my changes to verify that I didn't change the essence of your question?  
> **username_2**: We have really good answers below, and I would like to add a nice hack to them. On Bitcoin-Core, run the command `bitcoin-cli gettxoutsetinfo`. It will give you all the information of the coins outstanding. It calculates that amount by summing all the block subsidies less the amount not claimed by miners, bitcoins sent to `OP_RETURN` outputs, 50 BTC genesis block output that cannot be spent and the two coinbase transactions username_3 username_3 mentioned in his answers. It doesn't exclude the Bitcoins sent to `1BitcoinEater...` type addresses as thr is no verifiable way to know if one own the priv key.  
> **username_0**: This works indeed: ```root@b9f3dd35c755:/# bitcoin-cli gettxoutsetinfo {   "height": 601237,   "bestblock": "0000000000000000000f18a401591a0f440668ed1e3d975a64cb3687b796b8c6",   "transactions": 37206777,   "txouts": 63615267,   "bogosize": 4784113473,   "hash_serialized_2": "88e6d6b2585e83204760db1f383b942dbade97569c7556bdd30b1ad8fcfcdfa9",   "disk_size": 3833721332,   "total_amount": 18015292.32182326 } ```  But minus here if you don't have RPC access and using only public explorer to import data.  

---

## 3 answers

### Answer by username_5 on 2019-10-26. Score: 5 | Accepted answer

The first transaction in every block is called the coinbase transaction, it is a special transaction that pays the miner their reward. This transaction adheres to different rules than the rest: it has no inputs, but has output(s).

The coinbase transaction outputs are allowed to be equal to or less than the block subsidy (newly minted coins) + all transaction fees in the block.

The block subsidy is a set amount, as defined by the code. The subsidy started at 50 BTC, and that amount is cut in half every 210,000 blocks (25, 12.5, 6.25, etc).

The transaction fees for the block are found by taking the rest of the transactions in the block (ie everything that isn’t the coinbase transaction), and calculating the difference between the inputs and outputs in them. This value (input value - output value) is the implied fee.

Note that there are some odd cases to account for, [this question has a bunch of great info in this regard.](https://bitcoin.stackexchange.com/q/38994/63872)  in addition to this, there is a non-zero amount of BTC that has been ‘burned’, by being sent to addresses or scripts that are un-spendable, or at least have an extremely small chance of someone actually knowing the private key for them (eg the 1BitcoinEater... address). Depending on how you define ‘coin supply’, it may be worth account for these coins as well.


---

### Answer by username_3 on 2019-10-26. Score: 5

If you want the total amount of BTC created, you simply need to iterate through the coinbase transactions (first tx in every block) and add up the output. You will then need to subtract the transaction fees for that block to avoid double counting those.

If you want a somewhat accurate money supply, you will need to do the above, and then also subtract any BTC sent to `OP_RETURN` outputs.

There are also a number of burn addresses and accidental addresses which have had BTC sent to them, but are effectively locking the coins forever as no one has a private key or valid redeem script for them. You can attempt to subtract those, but it is not always possible to identify if an address falls into this category.

Lastly, there are two cases where coinbase transactions had the same txid, which results in burning of one of the outputs:

```
e3bf3d07d4b0375638d5f1db5255fe07ba2c4cb067cd81b84ee974b6585fb468
d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599

```


---

### Answer by username_4 on 2019-10-30. Score: 1

You can use my [parser](https://github.com/ragestack/blockchain-parser) for all the local BTC raw (real) data.

Then you can find all transactions with

`"TX from hash = 0000000000000000000000000000000000000000000000000000000000000000"`

and then

`"Value = XXXXXXXXXXXXXXXX"`

(`XX` - HEX string value of Byte) would be your incremental sum of coin supply.


---

