Skip to content

Instantly share code, notes, and snippets.

@ngotchac

ngotchac/main.js Secret

Last active August 28, 2019 18:50
Show Gist options
  • Save ngotchac/8b85622f6396001f243fa2323184104d to your computer and use it in GitHub Desktop.
Save ngotchac/8b85622f6396001f243fa2323184104d to your computer and use it in GitHub Desktop.
Parity Issue 9660
const ethers = require('ethers');
const readline = require('readline');
const account = ethers.Wallet.createRandom();
let nonce = 0;
let mined = 0;
console.log("Created account:", account.address);
async function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function sendTransaction(provider, signedTx) {
const txResult = await provider.sendTransaction(signedTx);
// console.log("Sending transaction", txResult.hash);
const txWaitResult = await txResult.wait();
// console.log("Mined transaction", txWaitResult.transactionHash, "at block", txWaitResult.blockNumber);
mined += 1;
const str = mined.toString();
process.stdout.write(str);
readline.moveCursor(process.stdout, -1 * str.length, 0);
}
async function run() {
const provider = new ethers.providers.JsonRpcProvider();
// const bn = await provider.getBlockNumber();
// console.log("Current block number:", bn);
const n = Math.ceil(Math.random() * 500);
// const n = 2;
// const n = 500;
const initNonce = nonce;
const transactions = await Promise.all(
Array.from(Array(n)).map(async (_, i) => {
const tx = {
nonce: initNonce + i,
gasLimit: 210000,
gasPrice: 0,
to: "0x88a5C2d9919e46F883EB62F7b8Dd9d0CC45bc290",
value: 0,
data: "0xaa" + i,
};
const signedTx = await account.sign(tx);
return signedTx;
})
);
nonce += n;
mined = 0;
const started = Date.now();
process.stdout.write(`Sending ${n} transactions... `);
await Promise.all(transactions.map((tx) => sendTransaction(provider, tx)));
const elapsed = Math.round(Date.now() - started) / 1000;
const speed = Math.round(n / elapsed * 1000) / 1000;
process.stdout.write(`Done ! ${elapsed}s - ${speed}tx/s\n`);
}
async function main() {
while (true) {
await run();
await sleep(250);
}
}
main()
.then(() => process.exit(0))
.catch((e) => {
console.error(e);
process.exit(1);
});
{
"name": "parity-issue-9660",
"version": "0.1.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"ethers": "^4.0.33"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment