Skip to content

Instantly share code, notes, and snippets.

@caderek
Last active June 28, 2022 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caderek/5d51e99e1fbb8370cee70397e531d1e0 to your computer and use it in GitHub Desktop.
Save caderek/5d51e99e1fbb8370cee70397e531d1e0 to your computer and use it in GitHub Desktop.
Bitcoin energy consumption calculator
const US_CONSUMPTION = 3930;
const halvings = [
new Date("2012.11.28").getTime(),
new Date("2016.07.09").getTime(),
new Date("2020.05.11").getTime(),
...new Array(30) // 30 more cycles until year 2140
.fill(0)
.map(
(_, i) =>
new Date("2020.05.11").getTime() + 210000 * 60 * 10 * 1000 * (i + 1)
),
];
const calc = ({ price, profit, cost, date, avgTXFee }) => {
const timestamp = new Date(date).getTime();
const maxTransactions = 7 * 60 * 10;
const exponent = halvings.findIndex((x) => timestamp < x);
const baseReward = exponent === -1 ? 0 : 50 / 2 ** exponent;
const baseReward$ = baseReward * price;
const feeReward$ = maxTransactions * avgTXFee;
const reward = baseReward$ + feeReward$;
const rewardsPerHour = reward * 6 * (1 - profit / 100); // 1 block every 10 minutes
const consumptionPerHour = Math.floor(rewardsPerHour / cost);
const consumptionPerYear = Math.floor(consumptionPerHour * 24 * 365);
console.log(
`
Date: ${date}
Base reward per block: ${baseReward} BTC
Fee rewards per block: ${feeReward$ / price} BTC
Total reward per block: ${baseReward + feeReward$ / price} BTC
BTC price: $${price}
Profit: ${profit}%
Cost per kWh: $${cost}
Consumption: ${(consumptionPerYear / 1e9).toFixed(3)} TWh / year
In comparison to US consumption: ${(
(consumptionPerYear / 1e9 / US_CONSUMPTION) *
100
).toFixed(1)} %
------------------------------------------------
`
);
};
// Examples:
calc({
price: 60000, // $
profit: 5, // %
cost: 0.11, // $ / kWh
date: "2021.11.01", // RRRR.MM.DD
avgTXFee: 10, // $
});
calc({
price: 20000, // $
profit: 5, // %
cost: 0.11, // $ / kWh
date: "2022.06.28", // RRRR.MM.DD
avgTXFee: 1, // $
});
calc({
price: 1000000, // $
profit: 5, // %
cost: 0.11, // $ / kWh
date: "2025.01.01", // RRRR.MM.DD
avgTXFee: 50, // $
});
/* Results
Date: 2021.11.01
Base reward per block: 6.25 BTC
Fee rewards per block: 0.7 BTC
Total reward per block: 6.95 BTC
BTC price: $60000
Profit: 5%
Cost per kWh: $0.11
Consumption: 189.288 TWh / year
In comparison to US consumption: 4.8 %
------------------------------------------------
Date: 2022.06.28
Base reward per block: 6.25 BTC
Fee rewards per block: 0.21 BTC
Total reward per block: 6.46 BTC
BTC price: $20000
Profit: 5%
Cost per kWh: $0.11
Consumption: 58.647 TWh / year
In comparison to US consumption: 1.5 %
------------------------------------------------
Date: 2025.01.01
Base reward per block: 3.125 BTC
Fee rewards per block: 0.21 BTC
Total reward per block: 3.335 BTC
BTC price: $1000000
Profit: 5%
Cost per kWh: $0.11
Consumption: 1513.847 TWh / year
In comparison to US consumption: 38.5 %
------------------------------------------------
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment