jsutil: correct the division

This commit is contained in:
emailtovamos 2024-05-21 15:42:58 +01:00
parent cb0b34b7c2
commit e149161d54

@ -4,6 +4,8 @@ import program from "commander";
// Usage: // Usage:
// node faucet_request.js --rpc localhost:8545 --startNum 39539137 // node faucet_request.js --rpc localhost:8545 --startNum 39539137
// node faucet_request.js --rpc localhost:8545 --startNum 39539137 --endNum 40345994 // node faucet_request.js --rpc localhost:8545 --startNum 39539137 --endNum 40345994
// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.bnbchain.org:8545 --startNum 39539137 --endNum 40345994
program.option("--rpc <Rpc>", "Rpc Server URL"); program.option("--rpc <Rpc>", "Rpc Server URL");
program.option("--startNum <Num>", "start block", 0); program.option("--startNum <Num>", "start block", 0);
program.option("--endNum <Num>", "end block", 0); program.option("--endNum <Num>", "end block", 0);
@ -28,7 +30,16 @@ const main = async () => {
let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock) let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock)
let endBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", endBlock) let endBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", endBlock)
let numFaucetRequest = (startBalance - endBalance) / 0.3 const faucetAmount = BigInt(0.3 * 10**18); // Convert 0.3 ether to wei as a BigInt
const numFaucetRequest = (startBalance - endBalance) / faucetAmount;
// Convert BigInt to ether
const startBalanceEth = Number(startBalance) / 10**18;
const endBalanceEth = Number(endBalance) / 10**18;
console.log(`Start Balance: ${startBalanceEth} ETH`);
console.log(`End Balance: ${endBalanceEth} ETH`);
console.log("successful faucet request: ",numFaucetRequest); console.log("successful faucet request: ",numFaucetRequest);
}; };
main().then(() => process.exit(0)) main().then(() => process.exit(0))