[SOLVED] BSC explorer Json data

Hy guys, iā€™m afraid iā€™m very unexperienced in this domain and i would need help on how to explore the binance smart chain and get data about tokens by contract address.
Like, price, total supply, circulating supply, and so on.
Any help is appreciated. Thank you.
I do have a moralis account and a live server on main net ā€¦ if this means anything.
But iā€™m stuck there.

PS, i found the Deep index api and i selected chain to query to BSC and Mainnet but,
i get this error:

Code Details
401

Undocumented|Error:

Response body

Download

"JWT missing"
Response headers|

I tried different token addresses and i get the same thing

1 Like

Hi inebunit,

When using the Deep Index API from your Dashboard you need to provide the master key to authorize the calls. See the Deep Index docs here:
https://docs.moralis.io/moralis-server/deep-index-api

You can also use the Convenience Functions plugs to get token and NFT balances for any address
https://docs.moralis.io/moralis-sdk/crypto-common-functions

In the future weā€™ll have some sort of built in way to get token price data, but for now the simplest way is to use the CoinGecko API. See their docs here:
https://www.coingecko.com/api/documentations/v3

Hope that helps.

thanks for the answer but i need prices data from the BSC tokensā€¦ all of them .
Coingeko doesnā€™t provide this.

We will offer onchain prices soon (probably in July)

thanks. looking forward to it

Update:
the https://docs.moralis.io/moralis-server/deep-index-api
seems to not exist anymore.
I am still trying to get token price from BSC and i get this error:
{ā€œmessageā€:ā€œAPI KEY missing from x-api-key headerā€}
would appreciate any help.
I need to post prices from BSC on my website.
Thank you.

Hi,
Try to go to https://admin.moralis.io/web3Api and there try a simple API from that list.

thatā€™s what i did and it came up with this link:
https://deep-index.moralis.io/api/v2/erc20/0x8e428aA75b271EbF905DB7e3F2970453E976481e/price?chain=bsc

Also, i donā€™t know what ProviderUrl means.

I used the /erc20/{address}/price
Choose BSC chain

You can ignore provider url for now.
I get this output:

{
  "nativePrice": {
    "value": "12738528727",
    "decimals": 18,
    "name": "Binance Coin",
    "symbol": "BNB"
  },
  "usdPrice": 0.00000474682112594,
  "exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
  "exchangeName": "PancakeSwap v2"
}

i get this:
{ā€œmessageā€:ā€œAPI KEY missing from x-api-key headerā€}

Also, the token name is not Binance coin ā€¦ but thatā€™s less important. Im mostly interested in the price.
https://poocoin.app/tokens/0x8e428aa75b271ebf905db7e3f2970453e976481e

Ok, try to refresh the page few times, it looks like it is a problem with generating the API key for your account. If the problem still persists, weā€™ll need to take a look at your account.

refreshed it like 5 times. Maybe i didnā€™t set something right?
I have to mention that iā€™m a noob so, donā€™t expect any system problems. Most probably itā€™s my fault.

What you see for the curl command?
I see something like this:

curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/erc20/0x8e428aA75b271EbF905DB7e3F2970453E976481e/price?chain=bsc' \
  -H 'accept: application/json' \
  -H 'X-API-Key: MY_API_KEY_HERE'
curl -X 'GET' \
  'https://deep-index.moralis.io/api/v2/erc20/0x8e428aa75b271ebf905db7e3f2970453e976481e/price?chain=bsc' \
  -H 'accept: application/json' \
  -H 'X-API-Key: <here is an apy key>
Should i post the api key also?

Also, i get this response in my moralis account:

{
  "nativePrice": {
    "value": "12651542928",
    "decimals": 18,
    "name": "Binance Coin",
    "symbol": "BNB"
  },
  "usdPrice": 0.00000475001883575,
  "exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
  "exchangeName": "PancakeSwap v2"
}

But when i access the link in another browser tab,
https://deep-index.moralis.io/api/v2/erc20/0x8e428aa75b271ebf905db7e3f2970453e976481e/price?chain=bsc
i get this:
{ā€œmessageā€:ā€œAPI KEY missing from x-api-key headerā€}

Ok, got it now, you can not use only that link to get the data, you also have to send the API key in the header request.

yes, i tested the curl here https://reqbin.com/req/c-vdhoummp/curl-get-json-example
and realized iā€™m way too noob for this. Thank you for your patience. Iā€™ll try to integrate it in my website.

1 Like

Hey there, I am having a similar issue - I can get a good response in some apps, but not all. Hereā€™s what it looks like in Xcode:

Any ideas? Thanks.

I donā€™t know how did you set that http header there. You can find here an example on how you should set that header value in curl: https://admin.moralis.io/web3Api after you try there a function.

this is how i used mine

//cURL price data from JSON				
$url = "https://deep-index.moralis.io/api/v2/erc20/" . $contract . "/price?chain=" . $network . "";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "accept: application/json",
   "X-API-Key: <your api key here>",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$resp = curl_exec($curl);
curl_close($curl);
	

$yummy = json_decode($resp);
$usdprice = @$yummy->usdPrice;
//end cURL price data from JSON	

iā€™m getting data from 2 chains. by contract.
also, gettin g data for each crypto in real time will make your site unbearable slow.
What i did was to set up a cron-job to run once an hour and populate database with the data for each crypto then pull data from data base with 1h term.

1 Like