-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdecimal.js
53 lines (48 loc) · 1.57 KB
/
decimal.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
import axios from "axios";
import { CG_API_KEY, tokens } from "./config.js";
import fs from "fs";
const globalDataArray = [];
const chunkArray = (array, size) => {
const result = [];
for (let i = 0; i < array.length; i += size) {
result.push(array.slice(i, i + size));
}
return result;
};
export const getDecimalByMintAddress = async() => {
const tokenChunks = chunkArray(tokens, 30);
for (const chunk of tokenChunks) {
const tokenArray = chunk.join("%2C");
const options = {
method: "GET",
url: `https://pro-api.coingecko.com/api/v3/onchain/networks/solana/tokens/multi/${tokenArray}`,
headers: {
accept: "application/json",
"x-cg-pro-api-key": CG_API_KEY,
},
};
try {
const response = await axios.request(options);
const data = response.data.data;
globalDataArray.push(
data.map(({ attributes }) => ({
address: attributes.address,
decimals: attributes.decimals,
}))
);
} catch (error) {
console.error(error);
}
}
fs.writeFile(
"tokenwithDecimal.json",
JSON.stringify(globalDataArray.flat(), null, 2),
(err) => {
if (err) {
console.error("Error writing to file", err);
} else {
console.log("Successfully wrote to globalDataArray.json");
}
}
);
};