This repository was archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_sender_multi_recipient.js
More file actions
66 lines (52 loc) · 2.11 KB
/
Copy pathsingle_sender_multi_recipient.js
File metadata and controls
66 lines (52 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require('dotenv').config();
const { ethers } = require('ethers');
const { mean, std: standardDeviation } = require('mathjs');
const fs = require('fs');
(async () => {
rpc = process.env.RPC
prefunded_key = process.env.PREFUNDED_KEY
// Connect to the Ethereum network
const provider = new ethers.JsonRpcProvider(rpc); // Change to your local node RPC URL
// Create The Sender wallet
const theSender = ethers.Wallet.createRandom().connect(provider);
// Transfer 110 ETH from the prefunded wallet to The Sender
const prefundedWallet = new ethers.Wallet(prefunded_key, provider);
let tx = await prefundedWallet.sendTransaction({
to: theSender.address,
value: ethers.parseEther('110')
});
await tx.wait();
// Create 100 more wallet addresses
const wallets = Array.from({ length: 100 }, () => ethers.Wallet.createRandom());
// Prepare the wallet data to be JSON-serialized
const walletData = wallets.map(wallet => {
return {
address: wallet.address,
privateKey: wallet.privateKey
};
});
// Convert the wallet data to a JSON string
const walletDataJson = JSON.stringify(walletData, null, 2);
// Write the JSON string to a local file named 'wallets.json'
fs.writeFileSync('wallets.json', walletDataJson);
console.log('Wallets and private keys have been saved to wallets.json');
// Transfer 1 ETH to each wallet and measure the time
let times = [];
for (const wallet of wallets) {
const startTime = process.hrtime();
tx = await theSender.sendTransaction({
to: wallet.address,
value: ethers.parseEther('1')
});
await tx.wait();
const endTime = process.hrtime(startTime);
const elapsedTime = endTime[0] * 1000 + endTime[1] / 1e6; // Convert to milliseconds
times.push(elapsedTime);
console.log(`Transaction to ${wallet.address} confirmed in ${elapsedTime} ms`);
}
// Calculate mean and standard deviation
const timesMean = mean(times);
const timesStdDev = standardDeviation(times);
console.log(`Mean confirmation time: ${timesMean} ms`);
console.log(`Standard deviation of confirmation time: ${timesStdDev} ms`);
})();