Required param address not provided using account from useMoralis

Looking for guidance on why account is problematic in this case… When I console.log(account) I get a valid address however still get the error Error: required param address not provided … It works when I hard-code it

const {isInitialized, Moralis, account, isWeb3Enabled} = useMoralis()
const fetchNFTs = async () => {
    const options = {
    chain: "rinkeby",
    address: account,

    };
  const wrldhorse = await Moralis.Web3API.account.getNFTs(options);
  let nftBalance = wrldhorse.result;
  console.log(nftBalance);
}
  useEffect(() => {
    if (isInitialized) {
        fetchNFTs()
    }
}, [isInitialized])

this code that you pasted works or is not working?

can you add console.log for those options?

The code works… Just the address giving me problems

you could hard code id for now then, I don’t know why it wouldn’t work without that now

It needs to be interchangeable between accounts… I’m assuming it’s a type issue but not really sure what conversion it requires

I’m not really sure what type const account = useMoralis; returns or what is attached to the constant

I checked and its a string - very weird it does not work when address: account, but works when I console.log(account) and copy paste the result in my console into the address parameter…

turns out it logs an object at first and then a string (rendered 4 times)

that address will work after web3 is enabled or user authenticated

web3 is enabled… wouldn’t fetch nfts otherwise

useEffect(() => {
if (isInitialized) {
fetchNFTs()
}
}, [isInitialized])

I used this

Also - surely it wouldn’t console.log if web3 wasn’t enabled

you could add more checks in that useEffect, like checking if web3 is enabled and add it to dependencies

1 Like

I have tried that. I’ve had this issue for a week now

thanks will figure it out

Following this resolves that.

Having such

  useEffect(() => {
    if (!isWeb3Enabled) enableWeb3();

    if (isInitialized && isWeb3Enabled) {
      fetchNFTs();
    }
  }, [isInitialized, isWeb3Enabled]);
1 Like