add load generator

This commit is contained in:
Giacomo Pasini 2025-04-23 16:30:21 +02:00
parent a0afbccc99
commit 365fa7c8b9
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// load-script-rate.js
import { ethers } from "ethers";
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function main() {
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
const sender = ethers.Wallet.fromPhrase(
"test test test test test test test test test test test junk"
).connect(provider);
const to = "0x1000000000000000000000000000000000000000";
const value = ethers.parseEther("0.01");
const maxTxs = 10000; // total number of txs to send
console.log(`Sending up to ${maxTxs} txs at ~1 tx/s…`);
let nonce = await provider.getTransactionCount(sender.address);
for (let i = 0; i < maxTxs; i++) {
// fireandforget each sendTransaction
sender.sendTransaction({ to, value, gasLimit: 21_000, nonce: nonce + i })
.then(tx => console.log(` → tx #${i} sent: ${tx.hash}`))
.catch(err => console.error(` ! error on tx #${i}:`, err));
await sleep(1000);
}
console.log("Done scheduling txs.");
}
main().catch(console.error);

View File

@ -0,0 +1,3 @@
{
"type": "module"
}