forked from cuongdcdev/stw4-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_simple_mint.js
63 lines (53 loc) · 2.08 KB
/
benchmark_simple_mint.js
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
import { KeyPair, keyStores, connect, Contract, utils } from 'near-api-js';
import { globalConfig } from './config.js';
import { v4 as uuidv4 } from 'uuid';
import chalk from 'chalk';
import fs from "fs";
if (process.argv.length < 3) {
console.error('Usage: node benchmark_simple_mint.js <path/to/account_list.csv>');
process.exit(1);
}
const csvFilePath = process.argv[2];
const startMintSimple = async (userAddress, userPrivateKey) => {
const gas = "300000000000000";
const keyPair = KeyPair.fromString(userPrivateKey);
const keyStore = new keyStores.InMemoryKeyStore();
const nearConfig = { ...globalConfig, ...{ keyStore: keyStore } };
await keyStore.setKey(nearConfig.networkId, userAddress, keyPair);
const nearConnection = await connect(nearConfig);
const account = await nearConnection.account(userAddress);
const contractPoint = new Contract(account, nearConfig.contractPoint, {
viewMethods: ['getPoint'],
changeMethods: ['mint'],
});
while (true) {
const waitTime = Math.floor(Math.random() * (1000 - 200 + 1) + 200);
await new Promise(resolve => setTimeout(resolve, waitTime));
console.log(chalk.black.bgYellow("✨ Start simple minting after ✨"));
try {
const rs = await contractPoint.mint({}, gas);
console.log(rs);
} catch (e) {
console.log("❌ mint error, retry after sometime~~:", e);
const waitTime = Math.floor(Math.random() * (3000 - 1000 + 1) + 1000);
await new Promise(resolve => setTimeout(resolve, waitTime));
}
}
};
const run = async () => {
const data = await fs.promises.readFile(csvFilePath, 'utf8');
const rows = data.trim().split('\n');
for (let i = 1; i < rows.length; i++) {
const [key, value] = rows[i].split(',');
try {
await startMintSimple(key, value);
} catch (e) {
console.error("Error in the try catch:", e);
}
}
};
run()
.then(() => {})
.catch((error) => {
console.error('An error occurred:', error);
});