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.
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.
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.
Yeah, sorry - I wasnāt able to upload more than one picture at a time. Hereās what the full request looks like in Swift:
func getHeldNFTs(walletAddress:String) {
// Prepare URL
let url = URL(string: "\(moralis.baseEndpoint)\(walletAddress)/nft?chain=\(chain)&format=decimal")
var request = URLRequest(url: url!)
// Set Request Headers
request.setValue(moralis.apiKey, forHTTPHeaderField: "X-API-Key")
// Perform Request
URLSession.shared.dataTask(with: request) {(data, response, error) in
if let responseData = try? JSONDecoder().decode(GetAllNFTResponse.self, from: data!) {
let total = responseData.total
print("\(total)")
}
}
.resume()
}
The original curl request (which works fine anywhere else) is:
curl -v \
-X GET \
-H "User-Agent: HTTPBot-iOS/2021.1" \
-H "X-API-Key: MY-API-KEY" \
"https://deep-index.moralis.io/api/v2/MY-WALLET-ADDRESS/nft?chain=mumbai&format=decimal"
Iām wondering if itās an issue with how Swift or Xcode requests the data. The POST requests work great; I can get data and pass it to an app without an issue. This simple one, thoughā¦
can you print somehow the url that you get here to check if it is the expected one?
hi there,
Where can I get MY-API-KEY?
Looking forward to any idea from anyone.