Skip to content

Instantly share code, notes, and snippets.

export const getUncommonSat = (blockHeight) => {
const initialReward = 5000000000; // 50 BTC in satoshis
const halvingInterval = 210000; // halving every 210,000 blocks
let totalSatoshis = 0;
let currentReward = initialReward;
for (let i = 0; i < blockHeight; i += halvingInterval) {
const blocksInThisEra = Math.min(halvingInterval, blockHeight - i);
totalSatoshis += blocksInThisEra * currentReward;
currentReward /= 2;
import { WebSocket } from 'ws';
const ws = new WebSocket('wss://mempool.space/api/v1/ws');
ws.on('open', () => {
console.log('Connected to mempool.space WebSocket');
ws.send(JSON.stringify({ 'track-mempool': true }));
});
ws.on('message', (data) => {
import express from 'express';
import { createServer } from 'http';
import cors from 'cors'
const app = express();
const server = createServer(app);
app.use(cors({
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
const fs = require('fs');
function logTxSize (value, max = 55000000000000) {
let scale = Math.ceil(Math.log10(value)) - 5
return Math.min(max || Infinity,Math.max(1, scale))
}
function processBtcTxData(data) {
const parsedData = (data);