-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper_convert_ether_to_wei.js
33 lines (29 loc) · 1.13 KB
/
helper_convert_ether_to_wei.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
const fs = require('fs');
const csv = require('csv-parser');
const { EOL } = require('os');
// CSV file paths
const inputCsv = '/Users/afa/Downloads/final_odg_airdrop.csv';
const outputCsv = '/Users/afa/Downloads/final_odg_airdrop2.csv';
let writeStream = fs.createWriteStream(outputCsv);
fs.createReadStream(inputCsv)
.pipe(csv({
headers: false // Tell csv-parser there are no headers
}))
.on('data', (row) => {
// row is now an array, access columns by indices
let address = row[0]; // assuming the address is in the first column
let amount = row[1]; // assuming the amount to multiply is in the second column
// Check if amount is a valid number
if(amount && !isNaN(amount)) {
let modifiedValue = BigInt(Math.round(parseFloat(amount) * Math.pow(10, 18)));
// Write the address and modified amount to the file separated by a comma
writeStream.write(`${address},${modifiedValue.toString()}${EOL}`);
}
})
.on('end', () => {
writeStream.end();
console.log('The CSV file was written successfully');
})
.on('error', (err) => {
console.error('Error writing CSV file:', err);
});