From 5b7a71e38e5320dc1621a1c8d9f32b7c4303b2a4 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 16 May 2024 12:25:25 +0100 Subject: [PATCH 1/3] jsutils: faucet balance --- cmd/jsutils/faucet_request.js | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cmd/jsutils/faucet_request.js diff --git a/cmd/jsutils/faucet_request.js b/cmd/jsutils/faucet_request.js new file mode 100644 index 0000000000..49d9daae66 --- /dev/null +++ b/cmd/jsutils/faucet_request.js @@ -0,0 +1,40 @@ +import { ethers } from "ethers"; +import program from "commander"; + +// depends on ethjs v6.11.0+ for 4844, https://github.com/ethers-io/ethers.js/releases/tag/v6.11.0 +// Usage: +// nvm use 20 +// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 +// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 --endNum 40345994 +program.option("--rpc ", "Rpc Server URL"); +program.option("--startNum ", "start block", 0); +program.option("--endNum ", "end block", 0); +program.parse(process.argv); + +const provider = new ethers.JsonRpcProvider(program.rpc); +const main = async () => { + var startBlock = parseInt(program.startNum) + var endBlock = parseInt(program.endNum) + if (isNaN(endBlock) || isNaN(startBlock) || startBlock == 0) { + console.error("invalid input, --startNum", program.startNum, "--end", program.endNum) + return + } + // if --endNum is not specified, set it to the latest block number. + if (endBlock == 0) { + endBlock = await provider.getBlockNumber(); + } + if (startBlock > endBlock) { + console.error("invalid input, startBlock:",startBlock, " endBlock:", endBlock); + return + } + + let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock) + let endBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", endBlock) + let numFaucetRequest = (startBalance - endBalance) / 0.3 + console.log("successful faucet request: ",numFaucetRequest); +}; +main().then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); From cb0b34b7c203ae8e34dc18b65592bccac9cdca04 Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Thu, 16 May 2024 14:34:11 +0100 Subject: [PATCH 2/3] jsutils: update logs --- cmd/jsutils/faucet_request.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/jsutils/faucet_request.js b/cmd/jsutils/faucet_request.js index 49d9daae66..fb7c288574 100644 --- a/cmd/jsutils/faucet_request.js +++ b/cmd/jsutils/faucet_request.js @@ -1,11 +1,9 @@ import { ethers } from "ethers"; import program from "commander"; -// depends on ethjs v6.11.0+ for 4844, https://github.com/ethers-io/ethers.js/releases/tag/v6.11.0 // Usage: -// nvm use 20 -// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 -// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 --endNum 40345994 +// node faucet_request.js --rpc localhost:8545 --startNum 39539137 +// node faucet_request.js --rpc localhost:8545 --startNum 39539137 --endNum 40345994 program.option("--rpc ", "Rpc Server URL"); program.option("--startNum ", "start block", 0); program.option("--endNum ", "end block", 0); From e149161d54b4fc8314a5edfaca65eba682787d2a Mon Sep 17 00:00:00 2001 From: emailtovamos Date: Tue, 21 May 2024 15:42:58 +0100 Subject: [PATCH 3/3] jsutil: correct the division --- cmd/jsutils/faucet_request.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/jsutils/faucet_request.js b/cmd/jsutils/faucet_request.js index fb7c288574..bd4179747b 100644 --- a/cmd/jsutils/faucet_request.js +++ b/cmd/jsutils/faucet_request.js @@ -4,6 +4,8 @@ import program from "commander"; // Usage: // 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 https://data-seed-prebsc-1-s1.bnbchain.org:8545 --startNum 39539137 --endNum 40345994 program.option("--rpc ", "Rpc Server URL"); program.option("--startNum ", "start block", 0); program.option("--endNum ", "end block", 0); @@ -28,7 +30,16 @@ const main = async () => { let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock) 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); }; main().then(() => process.exit(0))