forked from leapdao/paper-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathairdrop.js
75 lines (67 loc) · 2.68 KB
/
airdrop.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
const Web3 = require('web3');
const JSBI = require('jsbi');
require('dotenv').config();
const ethereumjsutil = require("ethereumjs-util");
const ethers = require('ethers');
const fs = require("fs");
const { sendFunds, getBalance, sleep } = require ('./helpers');
const CONFIG = {
dryRun: true, //Tells you what it would do without actually sending any txs
provider: 'https://staging-testnet.leapdao.org/rpc',
dispenser: {
priv: process.env.SENDING_PK,
address: "0x"+ethereumjsutil.privateToAddress(process.env.SENDING_PK).toString('hex')
},
tokenColor: 1,
amountToSend: '2000000000000000000'
};
const folder = 'wallets';
const batch = '0';
//use this to debug CONFIG
//console.log(CONFIG)
//process.exit(1)
const rpc = new ethers.providers.JsonRpcProvider(CONFIG.provider);
async function main() {
let accounts = fs.readFileSync(`./${folder}/addresses-${batch}.txt`).toString().trim().split("\n");
const totalToSend = String(JSBI.multiply(JSBI.BigInt(CONFIG.amountToSend), JSBI.BigInt(accounts.length)));
let balance;
let txHash;
let txReceipt;
balance = await getBalance(CONFIG.dispenser.address, CONFIG.tokenColor, rpc);
console.log(totalToSend, 'tokens will be sent to', accounts.length, 'addresses');
console.log('Dispenser address', CONFIG.dispenser.address);
console.log('Dispenser wallet balance:', String(balance));
if (CONFIG.dryRun) console.log('Dry run mode is enabled! No tokens will be dispensed!');
if(JSBI.LT(balance, JSBI.BigInt(totalToSend))) {
if(!CONFIG.dryRun) {
//throw new Error('Not enough funds in dispenser!');
} else {
console.log('Not enough funds in dispenser!');
}
}
for(let i = 0; i < accounts.length; i++) {
console.log(i, 'Dispensing', CONFIG.amountToSend, 'tokens to', accounts[i]);
balance = await getBalance(accounts[i], CONFIG.tokenColor, rpc);
if (String(balance) !== '0') {
console.log(' Address already funded(', String(balance), '). Skipping.');
continue;
}
if (!CONFIG.dryRun) {
txHash = await sendFunds(CONFIG.dispenser, accounts[i], CONFIG.amountToSend, CONFIG.tokenColor, rpc);
for(let i = 0; i <= 5; i++) {
await sleep(1000);
txReceipt = await rpc.send("eth_getTransactionReceipt", [txHash]);
if(txReceipt) break;
}
balance = await getBalance(accounts[i], CONFIG.tokenColor, rpc);
if (String(balance) === CONFIG.amountToSend) {
console.log(' Done');
} else {
console.log(' Failed! Expected balance:', CONFIG.amountToSend, 'actual: ', String(balance));
}
} else {
console.log(' Dry run mode enabled! Will not send tokens. Account balance:', String(balance));
}
}
}
main();