-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (45 loc) · 1.33 KB
/
index.ts
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
import Web3 from 'web3'
import fs from 'fs'
import path from 'path'
import readline from 'readline'
const web3 = new Web3('https://cloudflare-eth.com/')
type TAddressList = {
address: string,
amount: string
}
async function ensToAddress() {
const fileStream = fs.createReadStream('./airdrop.csv');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
})
let json: TAddressList[] = []
for await (const line of rl) {
const [address, amount] = line.split(',')
json.push({ address, amount })
}
const resolvedEnsAddressesPromises = json
.filter(({ address }) => address.endsWith('.eth'))
.map(async ({ address, amount }) => {
try {
const resolvedAddress = await web3.eth.ens.getAddress(address)
return {
address: resolvedAddress,
ensAddress: address,
amount
}
} catch (error: any) {
return {
address,
amount,
error: error.message
}
}
})
const resolvedEnsAddresses = await Promise.all(resolvedEnsAddressesPromises)
const addressesWithoutEns = json.filter(({ address }) => !address.endsWith('.eth'))
const result = JSON.stringify([...resolvedEnsAddresses, ...addressesWithoutEns], null, 2)
console.log(result)
fs.writeFileSync("./result.json", result)
}
ensToAddress()