-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathairdrop.js
34 lines (32 loc) · 978 Bytes
/
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
const shell = require('shelljs');
const _ = require("lodash");
const fs = require("fs");
const { deleteFile } = require('./index')
/**
* WARNING!!!!!
* This will execute your token transfer
* @param {*} amount
* @param {*} token
*/
const exeAirdrop = (amount, token, file) => {
const d = require(file);
const errors = [];
_.forEach(d,(v, i) => {
console.log(`Airdropping ${amount} to ${v.address} at count: ${i}/${d.length} recipients`);
// Execute the token transfer here
shell.exec(`spl-token transfer ${token} ${amount} ${v.address} --fund-recipient --allow-unfunded-recipient`);
// Push any accounts that have errors
if (shell.error()) {
errors.push(v);
}
});
// Write the error file - should be [] if none
deleteFile('data/errors.json');
fs.appendFile('data/errors.json', JSON.stringify(errors), function (err) {
if (err) return console.log(err);
console.log('Errors');
});
};
module.exports = {
exeAirdrop
}