Skip to content

Commit

Permalink
cmd/jsutils: add utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zlacfzy committed Dec 8, 2023
1 parent 15bebb3 commit 092fa06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/jsutils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ Install node.js dependency:
npm install
```
## Run
mainnet
mainnet validators version
```bash
npm run startMainnet
```
testnet
testnet validators version
```bash
npm run startTestnet
```
Transaction count
```bash
node gettxcount.js --rpc ${url} --startNum ${start} --endNum ${end}
```
31 changes: 31 additions & 0 deletions cmd/jsutils/gettxcount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ethers } from "ethers";
import program from "commander";

program.option("--rpc <rpc>", "Rpc");
program.option("--startNum <startNum>", "start num")
program.option("--endNum <endNum>", "end num")
program.parse(process.argv);

const provider = new ethers.JsonRpcProvider(program.rpc)

const main = async () => {
let txCount = 0;
let num = 0;
console.log("Find the max txs count between", program.startNum, "and", program.endNum);
for (let i = program.startNum; i < program.endNum; i++) {
let x = await provider.send("eth_getBlockTransactionCountByNumber", [
ethers.toQuantity(i)]);
let a = ethers.toNumber(x)
if (a > txCount) {
num = i;
txCount = a;
}
}
console.log("BlockNum = ", num, "TxCount =", txCount);
};

main().then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 092fa06

Please sign in to comment.