How to calculate circulating supply of coins in Bitcoin?

How to calculate circulating supply of coins in Bitcoin?

 

  • 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 last block with subsidy
last_block = (ARGV[0] || 6929999).to_i

# 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.



Source link

Leave a Comment

Your email address will not be published. Required fields are marked *