[SOLVED] 400 and Invalid Function GetNFTs errors

Iā€™m fairly new to interacting with blockchains so this could be something simple Iā€™ve misunderstood, but I am getting 400 errors and ā€˜Invalid function: ā€œgetNFTsā€ā€™ errors. Iā€™ve tried using some of the troubleshooting code samples posted on this forum to attempt to rule out an issue with my code but everything Iā€™ve tried gives me the same errors. MetaMask connects and signs as I think it should.
Hereā€™s the current code:

<html>
  <head>
    <!-- Moralis SDK code -->
    <script src="https://cdn.jsdelivr.net/npm/web3@latest/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-getnftbalances">Get NFT Balances</button>
    <button id="btn-logout">Logout</button>

    <script>
      // connect to Moralis server
      Moralis.initialize("OkTXIluu6w2ftgLQ2YeD5LIYHUbcBKWhc6Z9KHgz");
      Moralis.serverURL = "https://jok6y0o5mjko.usemoralis.com:2053/server";

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

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

      async function getNFTBalances() {
        const options = {chain: 'binance smart chain', address: '0x90099da42806b21128a094c713347c7885af79e2'};
        const nfts = await Moralis.Web3.getNFTs(options);
        console.log(nfts);
      }

      // bind button click handlers
      document.getElementById("btn-login").onclick = login;
      document.getElementById("btn-logout").onclick = logOut;
      document.getElementById("btn-getnftbalances").onclick = getNFTBalances;

    </script>
  </body>
</html>

And here is the console output:

moralis.js:21917 POST https://jok6y0o5mjko.usemoralis.com:2053/server/functions/getNFTs 400
dispatch @ moralis.js:21917
ajax @ moralis.js:21924
(anonymous) @ moralis.js:22028
Promise.then (async)
request @ moralis.js:22022
run @ moralis.js:427
run @ moralis.js:353
value @ moralis.js:5278
getNFTBalances @ test2.html:38
moralis.js:24018 Uncaught (in promise) Error: Invalid function: "getNFTs"
    at handleError (moralis.js:22050)
    at async HTMLButtonElement.getNFTBalances (test2.html:38)
_construct @ moralis.js:24018
Wrapper @ moralis.js:24422
(anonymous) @ moralis.js:8462
ParseError @ moralis.js:8513
handleError @ moralis.js:22050
async function (async)
getNFTBalances @ test2.html:38

The server is on 0.0.244 and Iā€™ve tried redeploying it a few times (and each time Iā€™ve been changing my Server URL and Application ID in the code) but that doesnā€™t seem to help.
Thanks

Hey @kyleacct

We already checking this problem. Please donā€™t reload the server now :man_mechanic:

Use chain: 'bsc' instead of chain: 'binance smart chain'

@kyleacct

Update your server. Now it should work correctly :man_mechanic:

Cool, that works now, thank you! Have a great day

1 Like

Iā€™m really new, Iā€™m trying to make a version of the ā€œhow to create your first dAppā€ and am experiencing this 400 error - moralis.js:29317 POST https://yz6bb2bokgsb.usemoralis.com:2053/server/functions/getNFTs 400

Maybe I missed a cloud function setup? I donā€™t seem to have all the functions of Moralis.Web3API codes?

My code:

getUserNFTs = async () => {
console.log(ā€˜get NFTs clickedā€™);
let nfts = await Moralis.Web3API.account.getNFTs();
console.log(nfts);
}

Hey @FunnyGuy

Please make sure you are using the latest version. If the version update will not help - share the console error message

Yes, this is the most current version. I started on this project only 2 days ago.

below is the console error message:

moralis.js:29317 POST https://yz6bb2bokgsb.usemoralis.com:2053/server/functions/getNFTs 400

from logs it looks like it didnā€™t receive the right parameters.

you can set chain and address parameters when you are not authenticated for Moralis.Web3API.account.getNFTs

Iā€™ve tried adding parameters, like chain and address, however it returns the same message with additional errors.

I tested now Moralis.Web3API.account.getNFTs with your server and it worked fine without any error, I also forced an error with an invalid chain

ā€¦
Iā€™m still getting the error message.
What did your code look like?

looks like I needed to re-authenticate - thank you for the hint