This one works for you with normal fetch:
https://api.opensea.io/api/v2/metadata/matic/0x2953399124F0cBB46d2CbACD8A89cF0599974963/0xc73a2bd5ca07bc427fe7140a6720c84ec8daf7a5000000000000280000000064
?
Right now it is very late for me so i will try it in 8h when i wake up
It doesnât. Here is one other url that also doesnt work on fetch neither with httprequest:
URL: https://api.zed.run/api/v1/horses/metadata/62377
And this one is also api.
But if i fetch this url in my function (without trying httprequest) it works - i get img name, âŚ:
async function getSearchNFTs(){
try{
let address = await callAPI(document.getElementById('addressInput').value);
console.log("in nfts, " + address);
const nfts = await allNFTs(address);
//Loop over the array
if(nfts.length == 0){
alert("Address invalid or it doesn't exist - try different one!")
$("#searchResults").empty();
$("#addressOrDomain").html("Address does not exsist, please try with another one!");
$("#numOfNFTs").html("Address does not exsist, please try with another one!");
$("#searchResults").html("<strong>Address does not have any NFTs, please try with other Address.</strong>");
$("#searchResultsDiv").show();
$("#searchAccordion").show();
}else{
$("#searchResults").empty();
$("#numOfNFTs").val("");
$("#addressOrDomain").val("");
nfts.forEach( e => {
console.log(e);
let url = e.token_uri;
console.log(url)
fetch(url)
.then(response => response.json())
.then(data => {
console.log(data)
let currentDiv = document.getElementById("searchResults");
let content = `
<div class="card" style="width: 18rem;">
<img src="${data.image}" class="card-img-top" id="img" alt="${data.name}">
<div class="card-body">
<h4 class="card-title">${data.name}</h4><hr>
<span class="card-text"><strong>Collection:</strong><span class="data">${e.name}</span><br>
<span class="card-text"><strong>Blockchain:</strong><span class="data">${e.chain}</span><br>
<span class="card-text"><strong>NFT Type:</strong><span class="data">${e.contract_type}</span></span>
</div>
</div>
`
currentDiv.innerHTML += content;
})
})
$("#addressOrDomain").html(address + ".");
$("#numOfNFTs").html((nfts.length -1) + " NFTs.");
$("#searchResultsDiv").show();
$("#searchAccordion").show();
}
}catch (err) {
console.log(err);
}
}
0xff9ffdcfade903f9e8d9bc0b8f530948c05d097d - address i am testing with. It has a lot of those horses which are fetched with function above but not with cloud function httprequest.
https://docs.moralis.io/moralis-server/web3-sdk/token#gettokenidmetadata doesnât work well for you?
Didnt tried it yet. It should work since i get all nfts in array. Will try it after school.
For me this URL returns Status Code: 404
and {"success": false}
when I put it in the browser. This would mean that it doesnât work.
You can try https://docs.moralis.io/moralis-server/web3-sdk/token#gettokenidmetadata, maybe it has all the data that you want to fetch.
What parameters did you use when calling that function?
I dont know they are all inside a loop. But it wokrs for some and for some not.
Looks like it isnt possible to get nft metadata from all nfts.
I talk about this function:
const options = { address: "0xd...07", token_id: "1", chain: "bsc" };
const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(options)
That has parameters, you can test it separately to see how it works.
I tested it in console seperatly it worked. But in function most worked but not all
What is an example that didnât work? I mean with what parameters didnât work.
This should be a temporary error, you can try again after 2-3 minutes.
So here are 2 that failed:
2021-09-29T14:06:34.802Z - Failed running cloud function getTokenIdMetadata for user MVainVDmeoCblOrbMBklnbH4 with:
Input: {"address":"0xb6a55e861e5f5aab81b2cef8793f4bac097f88d3","token_id":"45"}
Error: {"message":"[object Object]","code":141}
2021-09-29T14:06:34.697Z - Failed running cloud function getTokenIdMetadata for user MVainVDmeoCblOrbMBklnbH4 with:
Input: {"address":"0x2953399124f0cbb46d2cbacd8a89cf0599974963","token_id":"93084268948183484439357267895949697378867222742931717572378051732847858810980"}
Error: {"message":"[object Object]","code":141}
You need to specify the chain_id. Your collections are on matic
So it should be:
const options = {
address: "0xb6a55e861e5f5aab81b2cef8793f4bac097f88d3",
token_id: "45",
chain: "matic" };
const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(options)
Now it works thank you so so much i really apriciate it.
I have a few more questions:
How can i get image from this
i tried a lot of different things - none worked
You need to JSON.parse(metadata)
and you will be able to get the img link