Created
February 18, 2021 03:01
-
-
Save alejoasotelo/d8f11881dd1cee25d652da0d372da1f9 to your computer and use it in GitHub Desktop.
get BSC Tokens info from https://bscscan.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let search = async (name) => { | |
let response = await fetch('https://bscscan.com/searchHandler?term=' + encodeURIComponent(name) + '&filterby=0'); | |
response = await response.json(); | |
return response | |
.map((item) => { | |
item = item.split("\t"); | |
let data = item[2].split("~"); | |
return { | |
name: item[0], | |
address: item[1], | |
contractAddres: data[0], | |
url: data[1], | |
price: data[3], | |
validate: item[4] != "0" | |
}; | |
}); | |
} | |
console.log('Cake', (await search('cake'))[1].price); | |
console.log('Bake', (await search('bake'))[1].price); | |
console.log('Helmet', (await search('helmet'))[1].price); | |
console.log('BDO', (await search('bdo'))[1].price); | |
console.log('SBDO', (await search('sbdo'))[1].price); |
This one gives a result of 30 items, any way we can get next set of items?
or use any other API?
This one gives a result of 30 items, any way we can get next set of items?
or use any other API?
I don't know but you can use coingecko api (it's free) to search tokens. Coingecko has outdated prices (not real time) so you can search tokens with coingecko api's then use web3 to get the real time price from pancakeswap, apeswap, sushiswap or any uniswap fork.
You can get the real time price with this code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MustafaAnasKH99 @ezequiel9
Another way and better to get the price of a token is calling directly to the router (smart contract) of Pancake Swap v2 or another exchange.
For example, if you want to get the price from BakerySwap you change the ROUTER_ADDRESS variable to 0xcde540d7eafe93ac5fe6233bee57e1270d3e330f and it's ready to get the price.
Note: the router must always be a clone of Uniswap and the tokens must have liquidity in the exchange.