-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
46 lines (35 loc) · 979 Bytes
/
utils.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
const { toBN, fromWei } = require('web3-utils');
const fetch = require('node-fetch');
const tokenSource = 'https://tokens.honeyswap.org';
const getTokens = async () => {
let data = await fetch(tokenSource, {
methods: 'GET',
headers: { 'Content-Type': 'application/json', }
}).then(response => {
return response.json();
});
return data.tokens;
};
const tokenPriceSource = 'https://api.coingecko.com/api/v3/simple/token_price/xdai?';
const getTokenPrices = async (ids) => {
const params = new URLSearchParams({
vs_currencies: 'usd',
contract_addresses: ids
});
let data = await fetch(tokenPriceSource + params, {
method: 'GET',
headers: { 'Content-Type': 'application/json', },
}).then(response => {
return response.json();
});
return data;
}
const convertToNumber = (hex, decimals) => {
const balance = toBN(hex);
return fromWei(balance);
};
module.exports = {
convertToNumber,
getTokens,
getTokenPrices
};