-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (59 loc) · 1.74 KB
/
index.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
64
65
66
67
68
69
const { Conflux, Drip } = require('js-conflux-sdk');
const conflux = new Conflux({
url: 'https://main.confluxrpc.com',
networkId: 1029,
});
// 填入私钥
const privateKey = require('./config.json').privateKey;;
const account = conflux.wallet.addPrivateKey(privateKey);
const CrossSpaceCall = conflux.InternalContract('CrossSpaceCall');
async function main() {
while(true) {
try {
await oneRound();
console.log('One round finished');
} catch(err) {
console.error(err);
}
await waitMilliseconds(10 * 1000);
}
}
async function waitMilliseconds(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function oneRound() {
let hash;
let batch = 5;
let nonce = await conflux.getNextNonce(account.address);
// let nonce = await conflux.txpool.nextNonce(account.address);
for(let i = 0; i < batch; i++) {
try {
hash = await CrossSpaceCall.transferEVM('0xc6e865c213c89ca42a622c5572d19f00d84d7a16').sendTransaction({
from: account.address,
nonce: nonce + BigInt(i),
gasPrice: Drip.fromGDrip(5),
});
console.log(`Sending ${i}`, hash);
} catch(err) {
console.error(err);
break;
}
// await waitMilliseconds(100);
}
for(let i = 0; i < 30; i++) {
try {
if (!hash) break;
let receipt = await conflux.getTransactionReceipt(hash);
if (receipt){
break;
}
await waitMilliseconds(1000);
} catch(err) {
console.error(err);
}
}
}
main().catch(err => {
console.error(err);
process.exit(1);
});