[SOLVED] How to get all NFTs of some contract while logged out?

Howdy folks. I’m using

const options = {
        chain: "0x13881",
        token_address: collectionAddress,
      };
const nftData = await Moralis.Web3API.account.getNFTsForContract(options);

to get the nft data from certain collection. However this requires me to be autthenticated. How can I get the same data while not logged in?
Thank you very much

You can use the address parameter instead of using the currently logged in user’s address.

Example:

const options = {
  address: '0x25eDb46cBB7744De5507ebe50b5086D236B63073',
  token_address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',
};

const nftData = await Moralis.Web3API.account.getNFTsForContract(options);
console.log('nftData', nftData);

but won’t that only fetch the nfts in that contract that belong to “address”?

getNFTsForContract - Returns an object with the NFT count for the specified contract and an NFT array belonging to the given address for the specified contract (asynchronous)

If you want to get all the NFTs for a collection/contract, you need to use getAllTokenIds.

When trying to use getAllTokenIds while logged out Im getting the following 2 errors:
Failed to load resource: the server responded with a status of 400 ()
MoralisWeb3Api.js:333 Uncaught (in promise) Error: required param address not provided

you can set the address parameter explicitly to that API function

ohh I see, my mistake was that I was using “token_address” as the parameter name. It worked now, thanks!

1 Like