'API to get price of Binance Smart Chain token on PancakeSwap
I have address of a token and I need to get its price in BUSD or BNB. It's not a problem to use paid API, if there is no other way. This token may not be listed on popular listings so it would be nice to get price somehow directly from PancakeSwap.
Solution 1:[1]
Here is a way to get it directly from PancakeSwap
https://api.pancakeswap.info/api/v2/tokens/0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3
Solution 2:[2]
A friend of mine used Moralis. https://docs.moralis.io/introduction/readme https://docs.moralis.io/moralis-dapp/web3-api/token#gettokenprice
Maybe you can already do something with the documentation, I have otherwise asked my colleague for example code
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/erc20/0x42F6f551ae042cBe50C739158b4f0CAC0Edb9096/price?chain=bsc&exchange=PancakeSwapv2' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
Result:
{
"nativePrice": {
"value": "8409770570506626",
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"usdPrice": 19.722370676,
"exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"exchangeName": "Uniswap v3"
}
Greetings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TheDayIsDone |
Solution 2 |