MoralisWeb3 / Moralis-JS-SDK

Moralis Official Javascript SDK
https://docs.moralis.io
Other
368 stars 257 forks source link

Moralis.EvmApi.nft.getNFTMetadata errors with "Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase')" due to missing contract_type #672

Closed meseta closed 2 years ago

meseta commented 2 years ago

New Bug Report

Checklist

Issue Description

running Moralis.EvmApi.nft.getNFTMetadata() and then trying to use the result getter causes an error "Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase')"

This appears to be due to the underlying API endpoint not returning a value for contract_type which causes validateValidEvmcontractType to fail.

Steps + code to reproduce

const response = await Moralis.EvmApi.nft.getNFTMetadata({
  address: <some valid address>,
  tokenId: <some valid token>,
  chain: <some valid chain>,
});

console.log(response.result);

Actual Outcome

The following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at isValidEvmContractType (/workdir/.yarn/cache/@moralisweb3-evm-utils-npm-2.4.0-79bc4dd4cb-a134d8abf0.zip/node_modules/@moralisweb3/evm-utils/lib/dataTypes/EvmNftContractType.js:11:19)
    at validateValidEvmContractType (/workdir/.yarn/cache/@moralisweb3-evm-utils-npm-2.4.0-79bc4dd4cb-a134d8abf0.zip/node_modules/@moralisweb3/evm-utils/lib/dataTypes/EvmNftContractType.js:22:45)
    at EvmNft.parse (/workdir/.yarn/cache/@moralisweb3-evm-utils-npm-2.4.0-79bc4dd4cb-a134d8abf0.zip/node_modules/@moralisweb3/evm-utils/lib/dataTypes/EvmNft/EvmNft.js:317:204)
    at new EvmNft (/workdir/.yarn/cache/@moralisweb3-evm-utils-npm-2.4.0-79bc4dd4cb-a134d8abf0.zip/node_modules/@moralisweb3/evm-utils/lib/dataTypes/EvmNft/EvmNft.js:26:29)
    at EvmNft.create (/workdir/.yarn/cache/@moralisweb3-evm-utils-npm-2.4.0-79bc4dd4cb-a134d8abf0.zip/node_modules/@moralisweb3/evm-utils/lib/dataTypes/EvmNft/EvmNft.js:44:16)
    at ApiResultAdapter.apiToResult [as adapter] (/workdir/.yarn/cache/@moralisweb3-evm-api-npm-2.4.0-adf343c3e7-c1bff19f56.zip/node_modules/@moralisweb3/evm-api/lib/resolvers/nft/getNFTMetadata.js:25:39)
    at ApiResultAdapter.get (/workdir/.yarn/cache/@moralisweb3-api-utils-npm-2.4.0-bd941ed2e5-b57c5ebdde.zip/node_modules/@moralisweb3/api-utils/lib/resolvers/ApiResultAdapter.js:40:25)

Expected Outcome

The parsed result is successfully displayed

Environment

Running in node.js

Server

Client

Logs

MusabShakeel576 commented 2 years ago

I gave it a try, and everything went smoothly. What value are you using for chain?

meseta commented 2 years ago

after our team reached out to Moralis, it was confirmed that there was an issue on Moralis's end where the server was not returning the value. This was also reported by others, for example here: https://forum.moralis.io/t/solved-cannot-read-properties-of-undefined-reading-touppercase/19607/11

Since this appears to be resolved, I am closing issue