forked from huaigu/reth_miner
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpook.js
85 lines (73 loc) · 2.25 KB
/
pook.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
const dotenv = require("dotenv");
dotenv.config();
const { ethers } = require("ethers");
const TotalMint = 10;
const RPC_URL = "https://polygon.blockpi.network/v1/rpc/public";
const chainId = 137;
const contractAddress = "0xF9C4c674188089A7A5C608510360155147b9607b";
const price = ethers.utils.parseUnits("0.1");
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const privateKey = process.env.PRIVATEKEY;
const wallet = new ethers.Wallet(privateKey, provider);
const account = wallet.address;
const FgGreen = "\x1b[32m";
const FgYellow = "\x1b[33m";
const FgRed = "\x1b[31m";
async function mint() {
// const jsonData = {
// p: "rARB-20",
// op: "mint",
// tick: "rARB",
// solution: solution,
// amt: "10000",
// };
// const dataHex = ethers.utils.hexlify(
// ethers.utils.toUtf8Bytes(
// "data:application/json," + JSON.stringify(jsonData)
// )
// );
const dataHex = "";
const nonce = await provider.getTransactionCount(account);
// const gasPrice = await provider.getGasPrice();
// console.log(
// FgYellow,
// `=== Gas Price: ${(gasPrice / 1e9).toFixed(2)} gwei ===`
// );
const ga = ethers.utils.parseUnits("120", "gwei");
const tx = {
from: account,
to: contractAddress,
nonce: nonce,
gasPrice: ga,
gasLimit: ethers.utils.hexlify(57000),
chainId: chainId,
value: price,
};
const signedTx = await wallet.signTransaction(tx);
console.log(FgGreen, `signedTx : ${signedTx}`);
const receipt = await provider.sendTransaction(signedTx);
console.log(FgGreen, `receipt : ${receipt.hash}`);
//await to confirm
await provider.waitForTransaction(receipt.hash);
console.log(FgYellow, `Successful minted : ${receipt.hash}`);
}
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
const main = async () => {
let mintedCount = 0;
while (mintedCount < TotalMint) {
try {
await mint();
mintedCount++;
} catch (ex) {
console.error(ex);
logInfo(`${FgYellow}#-${mintedCount}: Failed to mint`);
}
}
};
const logInfo = (msg) => {
// log with datetime
console.log(`[${new Date().toLocaleString()}]: ${msg}`);
};
main();