getAllTokenIds detNativeBalance needs an address

Im following the clone open sea tutorial and i get the following erroe when trying to use the getalltokenids and getnativebalance methods


dont really understand why, Im new to react and it is making everything even more confusing it also makes it harder to post code if your having an issue.

import { useMoralisDapp } from "providers/MoralisDappProvider/MoralisDappProvider";
import { useEffect, useState } from "react";
import { useMoralisWeb3Api, useMoralisWeb3ApiCall } from "react-moralis";
import { useIPFS } from "./useIPFS";

export const useNFTTokenids = () => {
  const { token } = useMoralisWeb3Api();
  const { chainId } = useMoralisDapp();
  const { resolveLink } = useIPFS();
  const [NFTTokenids, setNFTTokenids] = useState([]);
  const {
    fetch: getNFTTokenids,
    data,
    error,
    isLoading,
  } = useMoralisWeb3ApiCall(token.getAllTokenIds, { chain: chainId, adress: "0x4Db1f25D3d98600140dfc18dEb7515Be5Bd293Af" });

  useEffect(() => {
    if (data?.result) {
      const NFTs = data.result;
      for (let NFT of NFTs) {
        if (NFT?.metadata) {
          NFT.metadata = JSON.parse(NFT.metadata);
          // metadata is a string type
          NFT.image = resolveLink(NFT.metadata?.image);
        }
      }
      setNFTTokenids(NFTs);
    }
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [data]);

  return { getNFTTokenids, NFTTokenids, error, isLoading };
};```

maybe you have to be authenticated for those to work when you use them without any parameter

im signed in to a wallet or do i need to try to authenticate some other way? this is from the clone open sea tutorial. i noticed their were lots of errors

its asking for an address but i hard coded one into the function already

usually you have to authenticate with Moralis, not only to connect the wallet, but setting the parameters to those functions should work when you are not authenticated too

but its geting ids for the token not the account

ok, it was a misunderstanding then for me, I thought that it needed the address and it didn’t have it, in case of getAllTokenIds you’ll have to provide all the parameters

looks like that may have worked for getalltokenids but i getnativebalance is still showing errors

i dont think this is it, the error call getNativeBalance, is that also a react moralis method?

I think that getNativeBalance will require an address and chain as parameters

is that a react moralis method? I cant find it anywhere in the repo and this ids the ethereum boilerplate

I’m not react expert, I know how it should work in vanilla js, you can also call vanilla js functions in react

lol i feel the same way about all this react stuff. I can see how the modular aspect can be more convenienient but good old javascript just makes more sense.

so now everyhing returns undefined an ive got this error,


its giving a specific error, never seen this code before

this has some examples in case that it helps you: https://github.com/MoralisWeb3/react-moralis

I had trouble finding a good example in the repo but doing some more testing i noticed this error. so I guesse it is a react deal. I honestly dont see whats wrong with vannilla js but I built the website initially with the clone rarible tutorial and I decided to switch to react because all the other repos are.

ok i know i said it before but this time im definitley close. it seams the issue is pretaining to asynchronous javascript with the formated results

import { useMemo } from "react";
import { useMoralis } from "react-moralis";
import { useMoralisWeb3Api, useMoralisWeb3ApiCall } from "react-moralis";
import { useIPFS } from "./useIPFS";

export const useNFTTokenids = (addr, limit = 10) => {
    const { token } = useMoralisWeb3Api();
    const { chainId } = useMoralis();
    const { resolveLink } = useIPFS();
    const getAllTokenIdsOpts = {
        chain: "Eth",
        address: '0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB',
        // limit: limit,
    };

    const {
        fetch: getNFTTokenIds,
        data,
        error,
        isLoading,
        isFetching,
    } = useMoralisWeb3ApiCall(
        token.getAllTokenIds,
        getAllTokenIdsOpts,
        { autoFetch: !!token && addr !== "explore" },
    );
    console.log(token);

    const NFTTokenids = useMemo(() => {
        console.log('fetching tokenIds data')
        if (!data?.result || !data?.result.length) {
            return data;
        }
         console.log(data)
        const formattedResult = data.result.map((nft) => {
            try {
                if (nft.metadata) {
                    const metadata = JSON.parse(nft.metadata);
                    const image = resolveLink(metadata?.image);
                    return { ...nft, image, metadata };
                }
            } catch (error) {
                return nft;
            }
            return nft;
        });

        return { ...data, result: formattedResult };
    }, [data]);
       

    return { getNFTTokenIds, data: NFTTokenids, error, isLoading, isFetching };
};



whats happening is trying to wrap them into this return using forrmatedresults isnt working

Solved. dont quit know how but I just re wrote the entire page an it works now, thanks for talking me throug it, Moralis truly dose have the best community!

1 Like