-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
45 lines (37 loc) · 1.42 KB
/
index.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
var IOTA = require('iota.lib.js');
var config = require('./config');
var iotajs = new IOTA({
'host': config.uri,
'port': config.port
});
//Takes a list of seeds and generates the first X addresses for each seed.
function generateAddresses() {
for (i = 0; i < config.seeds.length; i++) {
iotajs.api.getNewAddress(config.seeds[i].toUpperCase(), {'index': 0, 'total': config.nAddr}, function(_, addresses) {
getBalance(addresses); //Calls the getBalance function with all generated addresses as argument
});
};
};
//Takes a list of addresses as argument and should get the balance for each address
function getBalance(addresses) {
iotajs.api.getBalances(addresses, 100, function(error, inputs) {
var i = 0;
var totalValue = 0;
if(inputs != null && inputs.balances != null) {
inputs.balances.forEach(function(balance) {
totalValue += parseInt(balance);
if (parseInt(balance) > 0) {
console.log(i+1 + " The address " + addresses[i] + " has a balance of: " + parseInt(balance));
console.log("Balance detected!!!");
} else {
console.log(i+1 + " The address " + addresses[i] + " has a balance of: " + parseInt(balance));
};
i++
})
} else {
console.log(error);
}
console.log("All addresses of this seeds contain " + totalValue + " tokens!")
});
};
generateAddresses();