forked from xiaozaa/mintTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
130 lines (108 loc) · 3.75 KB
/
timer.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const AlchemyWeb3 = require("@alch/alchemy-web3");
const _ = require("lodash");
const Tx = require('ethereumjs-tx').Transaction
const abiDecoder = require('abi-decoder');
const ethers = require('ethers'); // Require the ethers library
const utils = require('ethers').utils;
const config = require('./config.js')
let json = require('./abi.json');
abiDecoder.addABI(json);
const { spawn, exec } = require("child_process");
function getJSON() {
console.log(json); // this will show the info it in firebug console
};
async function signTx(web3, fields = {}) {
const nonce = await web3.eth.getTransactionCount(config.fromAddress, 'latest');
console.log('nonce',nonce)
const transaction = {
'nonce': nonce,
...fields,
};
return await web3.eth.accounts.signTransaction(transaction, config.privateKey);
}
async function sendTx(web3, fields = {}) {
const signedTx = await signTx(web3, fields);
web3.eth.sendSignedTransaction(signedTx.rawTransaction, function(error, hash) {
if (!error) {
console.log("Transaction sent!", hash);
const interval = setInterval(function() {
console.log("Attempting to get transaction receipt...");
web3.eth.getTransactionReceipt(hash, function(err, rec) {
if (rec) {
console.log(rec);
clearInterval(interval);
}
});
}, 1000);
} else {
console.log("Something went wrong while submitting your transaction:", error);
}
});
}
function sendMinimalLondonTx(web3,data,toAddress,price, number) {
console.log('data',data, typeof data)
web3.eth.estimateGas({
from: config.fromAddress,
data: data,
to: toAddress,
value: web3.utils.toWei(price, 'ether') * parseInt(number),
}).then((estimatedGas) => {
console.log("estimatedGas", estimatedGas);
sendTx(web3, {
gas: estimatedGas,
maxPriorityFeePerGas: web3.utils.toHex(web3.utils.toWei(config.maxPriorityFeePerGas, 'gwei')),
maxFeePerGas: web3.utils.toHex(web3.utils.toWei(config.maxFeePerGas, 'gwei')),
to: toAddress,
value: web3.utils.toWei(price, 'ether') * parseInt(number),
data: web3.utils.toHex(data)
});
});
}
const pendingTrasactions = async () => {
let web3URL;
let targetContract;
let creator;
console.log('Network Mode:', config.network);
switch(config.network) {
//---------------- TEST USAGE-------------------------
case 'Rinkeby':{
web3URL = config.wssRinkeby;
targetContract = "";
creator = "";
break;
}
case 'Goerli':{
web3URL = config.wssGoerli;
targetContract = "";
creator = "";
break;
}
//-----------------------------------------------------
default: {
web3URL = config.wssMainnet;
targetContract = config.toAddress;
creator = config.creatorAddress;
}
}
console.log('Web3URL:', web3URL);
const web3 = AlchemyWeb3.createAlchemyWeb3(web3URL);
var contract = new web3.eth.Contract(json, targetContract);
//-----------------------------------------------------------------
//--------------- Change this function every time------------------
let extraData = await contract.methods.publicSalesMint(config.number);
//-----------------------------------------------------------------
//-----------------------------------------------------------------
let data = extraData.encodeABI();
setInterval(function(){
let date = Date.now();
console.log("Current time:",date);
if(date >= config.time*1000){
console.log("It's the time!!")
console.log("INPUT DATA",data);
sendMinimalLondonTx(web3,data,targetContract,config.price, config.number);
}
},3000);
//-----------------------------------------------------------------
// your code
};
pendingTrasactions();