forked from antron3000/UCASH-Withdrawals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistribute.js
More file actions
85 lines (74 loc) · 2.45 KB
/
distribute.js
File metadata and controls
85 lines (74 loc) · 2.45 KB
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 ethers = require('ethers');
const csv = require('csv-parse');
const fs = require('fs');
require('dotenv').config();
const contractABI = [{
"inputs": [
{
"internalType": "address[]",
"name": "recipients",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "amounts",
"type": "uint256[]"
}
],
"name": "distributeUCASH",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}];
async function readCSV() {
const records = [];
const parser = fs
.createReadStream('recipients.csv')
.pipe(csv.parse({
columns: true,
skip_empty_lines: true
}));
for await (const record of parser) {
records.push(record);
}
return records;
}
async function distributeUCASH() {
try {
// Read CSV data
console.log("Reading recipients from CSV...");
const recipients = await readCSV();
// Separate addresses and amounts
const addresses = recipients.map(r => r.address);
const amounts = recipients.map(r =>
ethers.utils.parseUnits(r.amount.toString(), 18)
);
// Connect to network
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// Connect to contract
const contractAddress = "";
const distributor = new ethers.Contract(contractAddress, contractABI, wallet);
console.log(`Preparing to send to ${addresses.length} recipients...`);
console.log("First few recipients:");
for (let i = 0; i < Math.min(3, addresses.length); i++) {
console.log(`${addresses[i]}: ${ethers.utils.formatUnits(amounts[i], 18)} UCASH`);
}
// Send transaction
console.log("\nSending distribution transaction...");
const tx = await distributor.distributeUCASH(addresses, amounts);
console.log("Transaction hash:", tx.hash);
console.log("Waiting for confirmation...");
const receipt = await tx.wait();
console.log("Transaction confirmed in block:", receipt.blockNumber);
} catch (error) {
console.error("Error:", error);
}
}
// Run the distribution
distributeUCASH()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});