Skip to content

Instantly share code, notes, and snippets.

@ajtransak
Created September 24, 2024 13:47
Show Gist options
  • Save ajtransak/b1ced3bc1600d2815a4f7002174dbf7a to your computer and use it in GitHub Desktop.
Save ajtransak/b1ced3bc1600d2815a4f7002174dbf7a to your computer and use it in GitHub Desktop.
Filter Networks for Crypto Symbol
const axios = require('axios');
const fs = require('fs');
const cryptoList = [
"SOL", "DAI", "EGLD", "ZIL", "ONE", "XLM", "SHIB", "VET", "ICP", "TON",
"PEPE", "CRO", "ATOM", "APE", "FLOW", "MNT", "XTZ", "MANA", "ALGO", "KSM",
"XEM", "NOT", "SEI", "HBAR", "SUSHI", "NEAR", "MKR", "BONK", "APT", "SUI",
"XDC", "CELO", "CHZ", "OSMO", "ZEN", "STX", "IOTA", "IMX", "KDA", "WRX",
"AR", "FLR", "GMX", "GLMR", "IOTX", "GLM", "KAVA", "ROSE", "ASTR", "INJ",
"CKB", "WAXP", "SUPER", "VRA", "ELF", "MASK", "VTHO", "LOOKS", "HIVE",
"TWT", "JOE", "SCRT", "HTR", "SLP", "UTK", "ARKM", "AVA", "DOCK", "SPS",
"SPA", "REVV", "DFI", "LTC", "MOVR"
];
// Function to fetch networks and write to the corresponding file
async function getCryptoNetworks(apiUrl, outputFile) {
try {
const response = await axios.get(`${apiUrl}/api/v2/currencies/crypto-currencies`, {
headers: {
'accept': 'application/json'
}
});
const cryptoData = response.data.response;
const tokenNetworks = cryptoList.reduce((acc, symbol) => {
acc[symbol] = []; // Initialize with an empty array
const token = cryptoData.find(token => token.symbol === symbol);
if (token) {
acc[symbol] = token.network.name ? [token.network.name] : [undefined]; // Use [undefined] if network name is not present
} else {
acc[symbol] = [undefined]; // Add [undefined] if the symbol is not found
}
return acc;
}, {});
fs.writeFileSync(outputFile, JSON.stringify(tokenNetworks, null, 2), 'utf-8');
} catch (error) {
console.error(`Error fetching data from ${apiUrl}:`, error.message);
}
}
// Fetch for both staging and production
getCryptoNetworks('https://api-stg.transak.com', 'networks-staging.json');
getCryptoNetworks('https://api.transak.com', 'networks-production.json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment