Created
August 19, 2026 23:00
-
-
Save leonsomed/0394c3be1f0aa567b2dfbc242f358753 to your computer and use it in GitHub Desktop.
Compute bitcoin stats like inflation, issued coins, rewards, and approximate halving date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function computeBitcoinStats() { | |
| const formatterNumer = new Intl.NumberFormat("en-US", {}); | |
| const formatterPercent = new Intl.NumberFormat("en-US", { | |
| maximumFractionDigits: 4, | |
| }); | |
| const formatterDate = new Intl.DateTimeFormat("en-US", { | |
| month: "long", | |
| year: "numeric", | |
| }); | |
| let height = 0; | |
| let lastReward = 0; | |
| let issued = 0; | |
| const SATS_IN_BTC = 100_000_000; | |
| const GENESIS_BLOCK_HEIGHT = 1231006505000; | |
| const BLOCKS_IN_YEAR = 144 * 365; | |
| while (true) { | |
| const epoch = Math.floor(height / 210_000) + 1; | |
| const reward = Math.floor((50 / 2 ** (epoch - 1)) * SATS_IN_BTC); | |
| issued += reward; | |
| if (reward !== lastReward) { | |
| console.log({ | |
| epoch: formatterNumer.format(epoch), | |
| height: formatterNumer.format(height), | |
| reward: formatterNumer.format(reward / SATS_IN_BTC), | |
| rewardSats: formatterNumer.format(reward), | |
| issuedSats: formatterNumer.format(issued), | |
| issuedBtc: formatterNumer.format(issued / SATS_IN_BTC), | |
| satsUntil21M: formatterNumer.format(21_000_000 * SATS_IN_BTC - issued), | |
| inflationRate: | |
| formatterPercent.format(((reward * BLOCKS_IN_YEAR) / issued) * 100) + | |
| "%", | |
| date: formatterDate.format( | |
| new Date(GENESIS_BLOCK_HEIGHT + height * 10 * 60 * 1000), | |
| ), | |
| }); | |
| lastReward = reward; | |
| } | |
| if (issued >= 21_000_000 * SATS_IN_BTC) { | |
| console.log({ issued }); | |
| break; | |
| } | |
| if (height > 10_000_000) { | |
| console.log("Aborting due to reaching block height 10m"); | |
| console.log({ | |
| issuedSats: formatterNumer.format(issued), | |
| issuedBtc: formatterNumer.format(issued / SATS_IN_BTC), | |
| satsUntil21M: formatterNumer.format(21_000_000 * SATS_IN_BTC - issued), | |
| }); | |
| break; | |
| } | |
| height++; | |
| } | |
| } | |
| computeBitcoinStats(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compute bitcoin stats like inflation, issued coins, rewards, and approximate halving date. This is a proof of concept to calculate whether it is possible to reach the acclaimed 21 million BTC (It is not).