Skip to content

Instantly share code, notes, and snippets.

@bhavya2611
Last active May 22, 2021 15:28
Show Gist options
  • Save bhavya2611/0c21eaf0d7cdecee66640230c76bbef3 to your computer and use it in GitHub Desktop.
Save bhavya2611/0c21eaf0d7cdecee66640230c76bbef3 to your computer and use it in GitHub Desktop.
// Get DOGECOIN price in ETH
const getDogecoinPriceInETH = async () => {
try {
const DOGECOIN = new Token(
ChainId.MAINNET, //ChainId for Ethereum Mainnet
"0x4206931337dc273a630d328da6441786bfad668f", //DOGECOIN address on Ethereum Mainnet
8 //Number of Decimals
);
const pair = await Fetcher.fetchPairData(DOGECOIN, WETH[DOGECOIN.chainId]);
const route = new Route([pair], WETH[DOGECOIN.chainId]);
return route.midPrice.toSignificant(6);
} catch (e) {
console.log(e);
return 0;
}
};
// Get DOGECOIN price in BNB
const getDodgecoinPriceInBNB = async () => {
try {
const response = await fetch("https://api.pancakeswap.info/api/v2/tokens");
const priceData = await response.json();
return priceData.data["0xbA2aE424d960c26247Dd6c32edC70B295c744C43"].price_BNB; //Address of DOGECOIN on BSC Mainnet
} catch (e) {
console.log(e);
return 0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment