Skip to content

Instantly share code, notes, and snippets.

@kouloumos
Created March 25, 2022 19:11
Show Gist options
  • Save kouloumos/a2ef2ee19d88914b1845cc74498535e7 to your computer and use it in GitHub Desktop.
Save kouloumos/a2ef2ee19d88914b1845cc74498535e7 to your computer and use it in GitHub Desktop.
Liquid Fees calculation
import fetch from "node-fetch";
const START_BLOCK = 1247561; // 2021-03-25 21:00
const END_BLOCK = 1761444; // 2022-03-25 21:00
const calculateBlockFees = async (blockHash) => {
const response = await fetch(
`https://liquid.network/api/block/${blockHash}/txs`
);
const txs = await response.json();
let total_block_fees = 0;
for (const tx of txs) {
total_block_fees += tx.fee;
}
return total_block_fees;
};
const getBlockHash = async (blockHeight) => {
const response = await fetch(
`https://liquid.network/api/block-height/${blockHeight}`
);
return await response.text();
};
const start = async () => {
let totalFees = 0;
for (let blockHeight = START_BLOCK; blockHeight <= END_BLOCK; blockHeight++) {
const blockHash = await getBlockHash(blockHeight);
const blockFees = await calculateBlockFees(blockHash);
console.log(`height: ${blockHeight}, fees: ${blockFees}`);
totalFees += blockFees;
}
const bitcoin = totalFees / 100000000;
console.log(`Total Fees = ${bitcoin} L-BTC`);
};
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment