Fetch NFT OpenSea empty array [SOLVED]

Hey guys,

When I fetch my NFTs always returns an empty array,

I have NFT’s Rarible and OpenSea,

https://opensea.io/assets/matic/0x9928a8ea82d86290dfd1920e126b3872890525b3/88208
https://opensea.io/assets/0x60f80121c31a0d46b5279700f9df786054aa5ee5/1115198

  const getNonFungibleTokens = async () => {
    if (isAuthenticated) {
      const userEthNFTs = await Moralis.Web3.getNFTs();
      console.log(userEthNFTs);
      const options = { chain: "matic" };
      const polygonNFTs = await Moralis.Web3.getNFTs(options);
      console.log(polygonNFTs);
      return polygonNFTs;
    }
  };

Thank you,

Renan Lopes

1 Like

That code looks ok to me. There might be an error in another part of your code. Try using this boilerplate test code, replace your Moralis App Id and server url, then type the getNFTs() query into the console (or add a function call to the snippet). I use a snippet like this for testing a lot. Hard code all the values.

<html>
  <head>
    <!-- Moralis SDK code -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>
  </head>
  <body>
    <h1>Moralis Test</h1>

    <button id="btn-login">Moralis Login</button>
    <button id="btn-logout">Logout</button>

    <script>
      // connect to Moralis server
      Moralis.initialize("YOUR MORALIS APP ID");
      Moralis.serverURL = "YOUR MORALIS SERVER URL";

      async function login() {
        let user = Moralis.User.current();
        if (!user) {
          user = await Moralis.Web3.authenticate();
        }
        console.log("logged in user:", user);
        getStats();
      }

      async function logOut() {
        await Moralis.User.logOut();
        console.log("logged out");
      }

      // bind button click handlers
      document.getElementById("btn-login").onclick = login;
      document.getElementById("btn-logout").onclick = logOut;
    </script>
  </body>
</html>

The issue is on the function itself is returning 400 when Eth chain is called,

There are two issues, one is that the default wallet address for the logged user is not being set, the second issue is that when calling Eth chain have some conversion error on this function,

1 Like

Thanks for reporting these bugs! Fixes for both the parse error and user address error will be in an upcoming Moralis Server version.

1 Like

This should be fixed in Moralis Server version 0.0.238. Please update your server and let us know if you still experience issues. :raised_hands:

1 Like

Awesome, works now getting the data from the database, thanks

1 Like