-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
108 lines (71 loc) · 2.4 KB
/
main.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
#!/usr/bin/env node --async-stack-traces
require('dotenv').config();
const Web3 = require('web3');
const csv = require('csv-parser')
const fs = require('fs')
let minABI = [
// transfer
{
"constant": false,
"inputs": [{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [{
"name": "",
"type": "bool"
}],
"type": "function"
}
];
function handlePaymentCSV() {
const payments = [];
let res2 = fs.createReadStream('payments.csv')
.pipe(csv())
.on('data', (data) => payments.push(data))
.on('end', () => {
sendAllTransactions(payments)
});
}
async function sendOneTransaction(web3, contract, toAddress, raw_amount, transCount) {
let fromAddress = web3.eth.accounts.wallet["0"].address
let amount = web3.utils.toWei(raw_amount, 'ether');
var gasLimit = 50000;
let gasPrice = await web3.eth.getGasPrice()
try {
payload = {
from: fromAddress,
gasPrice: web3.utils.toHex(Math.floor(gasPrice * 1.5)),
nonce: transCount,
gasLimit: web3.utils.toHex(gasLimit)
}
info = await contract.methods.transfer(toAddress, amount).send(payload);
console.log(`${raw_amount} sent to ${toAddress}, tx: ${info.transactionHash}`)
} catch (e) {
console.log({ e })
}
}
async function sendAllTransactions(payments) {
const TOKEN_ADDRESS = '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619';
const web3 = new Web3('https://polygon-rpc.com/');
let contract = new web3.eth.Contract(minABI, TOKEN_ADDRESS);
const privateKey = process.env.PRIVATE_KEY
web3.eth.accounts.wallet.add(web3.eth.accounts.privateKeyToAccount(privateKey))
let fromAddress = web3.eth.accounts.wallet["0"].address
console.log(`Sending payments from '${fromAddress}' to ${payments.length} accounts.`)
let transCount = await web3.eth.getTransactionCount(fromAddress)
for (const payment of payments) {
// console.log({transCount})
await sendOneTransaction(web3, contract, payment["WALLET"], payment["AMOUNT"], transCount)
transCount = transCount + 1
}
}
(async function main() {
handlePaymentCSV()
})();