Last active
November 15, 2023 06:33
-
-
Save allada/0945d67950f3fb6c4ed0dc3c4b4359cc to your computer and use it in GitHub Desktop.
This file contains 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
const ethers = require('ethers'); | |
const process = require('process'); | |
// Delay to wait to calculate blocks per second in seconds. | |
const delay = 60 * 60; | |
// To run: | |
// node getStatus.js /path/to/bsc/node/geth.ipc | |
async function run() { | |
const path = process.argv[2]; | |
const provider = new ethers.providers.IpcProvider({ | |
path | |
}); | |
function checkHeight(pos) { | |
const randomAddress = '0x8ce4b8039e335829292d825b32922d72b28a4905'; | |
return provider.getBalance(randomAddress, pos); | |
} | |
let left = 0; | |
let right = await provider.getBlockNumber(); | |
while (left <= right) { | |
const mid = Math.floor((right + left) / 2); | |
try { | |
await checkHeight(mid); | |
right = mid - 1; | |
} catch (e) { | |
left = mid + 1; | |
} | |
} | |
foundPosition = left; | |
right = await provider.getBlockNumber(); | |
console.log(" ", foundPosition, "-", right); | |
console.log("Calculating per minute...") | |
const current = await provider.getBlockNumber(); | |
setTimeout(async () => { | |
const final = await provider.getBlockNumber(); | |
console.log("Per second:", (final - current) / (delay)); | |
}, delay * 1000) | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment