[Help Needed] syncNFTContract, getNFTOwners, general questions:

Hello to whomever is reading this, I need some help with the syncNFTContract and the getNFTOwners API Calls.
First off, I would like to give some backstory as to some problems I overcame getting to where I am at now. I am running node v16.15.0, I learned about moralis about a week ago and thought it would be good for what I was looking to accomplish. In the process of trying to setup moralis in node JS on VSCode, I kept running into the problem of TypeError: Moralis.start is not a function. I came across this forum post: https://forum.moralis.io/t/solved-moralis-v2-typeerror-moralis-start-is-not-a-function/19090 and saw the recommendation to another forum post within the replies by a moderator, that said to change:
import Moralis from “moralis”
const Moralis2 = Moralis.default

“and then use Moralis2 instead of Moralis”

This worked for me as far as I know as it seemed to “partially” fix the problem but may be leading to some other problems I am having which is why I gave this backstory.

Anyways so I will show what my code and folder format looks like:
Screen Shot 2022-09-13 at 5.49.55 AM

The Address and API are correct on my end I just changed it for the screenshots. When I ran the syncNFTContract on a rinkeby NFT contract I have deployed for testing, I got the terminal response of “{ success: true }”, yet my NFT collection did not update to the new metadata (From one test image to a new IPFS link of another set of test images). I have also noticed and I don’t know if this is relevant but on my usage tab on my moralis account, it claims I have 0 CU or API Calls from my Web3API key. Am I supposed to be using a different API key than the Web3 one and is this a sign that something is wrong?

Regarding the issue I am having with getNFTOwners, when I call it, I get a response like this for each individual NFT in the collection:
Screen Shot 2022-09-13 at 6.15.48 AM

There is more with each NFT but I cut it out from screenshot. Anyways, what I am attempting to accomplish with this is to get a full list of NFT owners of an NFT, as well as how many they own. Why is it that for ownerOf: returns [EvmAddress] and not the address of the owner. I have noticed in the v1 docs it says “Make sure to include a sort parm on a column like token_id for consistent pagination results”, as well as an (options) section. Is there anyways that I can limit it so that it only tells me the ownerOf each address? Is there anyway through these options, to make it do what I am looking for? Ex. if address 0x05 owns 7 then it lists 7? I’d assume this isn’t possible and I will have to write some sort of other code based off of the output to the terminal to sort through and make the list I am looking for.

I am sorry that this is such a long list of questions, any help would be greatly appreciated as Moralis clearly is a powerful tool for developers! Thanks in advance.

For first question you will have to use resyncMetadata endpoint with a specific token id for the metadata to update. You will have to use it with your own api key.

For the second question, you could try the api endpoint directly in docs page: docs.moralis.io or directly with the swagger to see how the raw data looks like. It should return all the info that you need.

1 Like

So I was able to use the swagger UI as well as the NFT Endpoint. So your saying there is no way for it to automatically refresh all metadata at once so that the collection is updated? On the website at syncNFTContract, it claims “Initiates a metadata refresh for an entire NFT collection.”. When I am in the swagger UI and click the authorize lock button, I am supposed to put my Web3 API key there right? Then I can use the API calls? Also the thing that I am most wondering about is how to get a list of all owners of an NFT. I tried the call on the BAYC contract and it only listed 100 of the token ID’s and their owners, not all 10,000. Thanks in advance.

When I am in the swagger UI and click the authorize lock button, I am supposed to put my Web3 API key there right?

Yes that’s where you put in your Web3API key.

I tried the call on the BAYC contract and it only listed 100 of the token ID’s and their owners, not all 10,000

Pages/results are limited to a maximum size of 100, so you need to use the cursor parameter to get the next page - you can try using cursor from this page (and put your API key under Authentication if needed or use test).

Thanks, how do I use the cursor though? I read the docs and only saw examples for node JS implementation. If I just want it to start a new page after every 100 NFTs, what do I put in the cursor part of the swagger UI? Also is there any way to sort the responses to be the order of the ID’s and is there anyway to limit how much data it tells me for each NFT? What I mean by this is it only tell me the token ID and the owner of that token ID? If this is not possible that is fine.

When you make the first request, you get a cursor string in the response. If you pass (copy the string into the cursor field) it into the next request (with the same address, chain, etc.), you will get the next page, and so on.

You can test it from that API docs page (The cursor returned in the previous response (used to getting the next page)) or do the same in Swagger.

Also is there any way to sort the responses to be the order of the ID’s

You will need to do this yourself manually e.g. after paginating through and getting all the results.

is there anyway to limit how much data it tells me for each NFT

No.

I see, I got the cursor to work with the method you explained, thanks for this!!

One last question though, do the pages return the same token ID’s every time? I was gone for like 20 minutes after getting page 1 to work and wondering how to continue getting other pages. By the time I was back and re did page one to do the method you were saying, the results on page 1 were different from when I had originally done page 1. My concern is if there is a 5000 NFT collection and I need to do this 50 times, will I actually get a list of all the owners, or will it have changed the results and not given it to me correctly?

If you’re using a valid cursor for each request i.e. if it returns the next page, it should give the right results.