I am not able to understand how circulating supply is calculated by websites like CoinGecko. What does circulating supply mean here - is it the number of coins already minted? If so, how is that calculated?
- The first blocks had a 50 BTC subsidy
- The subsidy of block 0 is unspendable
- This subsidy is cut in half every 210.000 blocks
- Block height now is 704558
This script (in Ruby) calculates the total amount of Bitcoins issued.
#!/usr/bin/env ruby # first 210.000 blocks get 50 BTC as subsidy. # for every 210.000 blocks, the subsidy is cut in half. # global constants SATOSHIS_PER_COIN = 100000000 BLOCKS_PER_EPOCH = 210000 # given a block height, returns the subsidy for that block def block_subsidy(block_height) epoch = block_height / BLOCKS_PER_EPOCH subsidy = 50 * SATOSHIS_PER_COIN subsidy >> epoch end # get block height from command line or use default last_block = ARGV.to_i || 704558 # total supply, use 0.0 to make it a float total_supply = 0.0 # starts with 1 since subsidy of block 0 is unspendable for height in 1..last_block total_supply += block_subsidy(height) end # show total supply in bitcoins puts total_supply / SATOSHIS_PER_COIN
Having said that, there were some issues in some blocks, so the true total supply will be slightly less than this.