forked from austintgriffith/paper-wallet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathairdrop.js
77 lines (69 loc) · 2.97 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
76
77
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: JSON.parse(process.env.DRY_RUN) || false, //Tells you what it would do without actually sending any txs
provider: 'https://testnet-node.leapdao.org',
dispenser: {
priv: process.env.SENDING_PK,
address: "0x"+ethereumjsutil.privateToAddress(process.env.SENDING_PK).toString('hex')
},
tokenColor: 3,
amountToSend: '3000000000000000000',
topUp: false //use this for adding funds to already funded wallets (account will not be checked if it has funds or not)
};
const folder = 'wallets-ebt';
const batch = 'pa6';
//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 (!CONFIG.topUp && 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;
}
const expectedBalance = CONFIG.topUp ? String(JSBI.add(balance, JSBI.BigInt(CONFIG.amountToSend))) : CONFIG.amountToSend;
balance = await getBalance(accounts[i], CONFIG.tokenColor, rpc);
if (String(balance) === expectedBalance) {
console.log(' Done');
} else {
console.log(' Failed! Expected balance:', expectedBalance, 'actual: ', String(balance));
}
} else {
console.log(' Dry run mode enabled! Will not send tokens. Account balance:', String(balance));
}
}
}
main();