forked from MyEtherWallet/MyEtherWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchEthListData.js
53 lines (47 loc) · 2.08 KB
/
fetchEthListData.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
46
47
48
49
50
51
52
53
const fetch = require('node-fetch')
const fs = require('fs')
const tokenFolder = './src/tokens'
const contractFolder = './src/contracts'
async function fetchTokens () {
try {
if (!fs.existsSync(tokenFolder)) {
fs.mkdirSync(tokenFolder);
}
const tokenList = await fetch('https://api.github.com/repos/MyEtherWallet/ethereum-lists/contents/dist/tokens').then(res => res.json()).catch(err => console.log(err));
const tokenFileURL = 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/dist/tokens/';
if (tokenList !== undefined && tokenList.length > 0) {
tokenList.forEach(async (tokenFile) => {
let tokensCollection = await fetch(`${tokenFileURL + tokenFile.name}/tokens-${tokenFile.name}.json`).then(res => res.json()).catch(err => console.log(err));
if (tokensCollection !== undefined) {
fs.writeFileSync(`${tokenFolder}/tokens-${tokenFile.name}.json`, JSON.stringify(tokensCollection));
}
})
}
} catch (e) {
console.error(e); // todo replace with proper error
}
}
async function fetchContracts () {
try {
if (!fs.existsSync(contractFolder)) {
fs.mkdirSync(contractFolder);
}
const contractList = await fetch('https://api.github.com/repos/MyEtherWallet/ethereum-lists/contents/dist/contracts').then(res => res.json()).catch(err => console.log(err));
const contractFileURL = 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/dist/contracts/';
if (contractList !== undefined && contractList.length > 0) {
contractList.forEach(async (contractFile) => {
let contractsCollection = await fetch(`${contractFileURL + contractFile.name}/contract-abi-${contractFile.name}.json`).then(res => res.json()).catch(err => console.log(err));
if (contractsCollection !== undefined) {
fs.writeFileSync(`${contractFolder}/contract-abi-${contractFile.name}.json`, JSON.stringify(contractsCollection));
}
})
}
} catch (e) {
console.error(e); // todo replace with proper error
}
}
function run () {
fetchTokens()
fetchContracts()
}
run()