Skip to content

Instantly share code, notes, and snippets.

@alejoasotelo
Created February 18, 2021 03:01
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejoasotelo/d8f11881dd1cee25d652da0d372da1f9 to your computer and use it in GitHub Desktop.
Save alejoasotelo/d8f11881dd1cee25d652da0d372da1f9 to your computer and use it in GitHub Desktop.
get BSC Tokens info from https://bscscan.com
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);
@vin-the-dev
Copy link

This one gives a result of 30 items, any way we can get next set of items?

or use any other API?

@alejoasotelo
Copy link
Author

alejoasotelo commented Sep 7, 2021

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