-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·39 lines (35 loc) · 1.15 KB
/
script.js
File metadata and controls
executable file
·39 lines (35 loc) · 1.15 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
var Web3 = require("web3");
const { addresses } = require("./whiteListed.js");
var web3 = new Web3();
const dotenv = require("dotenv").config();
//console.log(process.env.PRIVATE_KEY);
// file system module to perform file operations
const fs = require("fs");
let data = {};
addresses.forEach(async (e, i) => {
const messageHash = web3.utils.soliditySha3(e.addr, e.qty_allowed, e.free);
// Signs the messageHash with a given account
const signature = await web3.eth.accounts.sign(
messageHash,
process.env.PRIVATE_KEY
);
//add quantity to signature
//add data to one big object
signature["qty_allowed"] = e.qty_allowed;
signature["free"] = e.free;
data[e.addr] = signature;
//output json file as a whole at the end
if (i + 1 == addresses.length) {
console.log(data);
// stringify JSON Object
var jsonContent = JSON.stringify(data);
console.log(jsonContent);
fs.writeFile("./output.json", jsonContent, "utf8", function (err) {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
});
}
});