[SOLVED] Cannot read properties of undefined (reading 'toUpperCase')

require('dotenv').config();
var Moralis = require('moralis').default;
var EvmChain = require('@moralisweb3/evm-utils');
var response
var chain = EvmChain.ETHEREUM;
var address 

 get_nfts = async () => {
            await Moralis.start({
                apiKey: '',
                // ...and any other configuration
            });
            response = await Moralis.EvmApi.account.getNFTs({
                address,
                chain,
            });
            return response

        }

        var results = get_nfts()
        results.then(response => {
            console.log(response.result)
        })
C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNftContractType.js:11
  ^switch (value.toUpperCase()) {
TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at isValidEvmContractType (C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNftContractType.js:11:19)
    at validateValidEvmContractType (C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNftContractType.js:22:45)
    at Function.EvmNft.parse (C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNft\EvmNft.js:73:192)
    at new EvmNft (C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNft\EvmNft.js:24:29)
    at Function.EvmNft.create (C:\Work\NFT.community\node_modules\@moralisweb3\evm-utils\lib\dataTypes\EvmNft\EvmNft.js:30:16)
    at C:\Work\NFT.community\node_modules\@moralisweb3\evm-api\lib\resolvers\account\getNFTs.js:27:43
    at Array.map (<anonymous>)
    at ApiPaginatedResultAdapter.apiToResult [as _adapter] (C:\Work\NFT.community\node_modules\@moralisweb3\evm-api\lib\resolvers\account\getNFTs.js:26:77)
    at ApiPaginatedResultAdapter.get (C:\Work\NFT.community\node_modules\@moralisweb3\api-utils\lib\resolvers\ApiResultAdapter.js:31:25)
    at C:\Work\NFT.community\router\landing_page.js:38:46
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

I am using the version [email protected]
The same endpoint was working yesterday but suddenly has stopped working today .

try to log that value, it looks like the value is undefined based on that error

{
  total: 5,
  page: 1,
  page_size: 100,
  cursor: null,
  result: [
    {
      token_address: '0xad404ba268c22ed94555ed2cad9cf80e3dffda63',
      token_id: '7835',
      amount: '1',
      owner_of: '0xb82eee8676682176a18cf4642d5f1af8fd9149a9',
      token_hash: '799cbac3999d3b58865d5e99616820e8',
      block_number_minted: '14850553',
      block_number: '15476424',
      token_uri: 'https://api.beatmyteam.com/bmt/7835',
      metadata: null,
      last_token_uri_sync: '2022-05-26T22:35:26.619Z',
      last_metadata_sync: '2022-05-27T05:06:35.867Z'
    },
    {
      token_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
      token_id: '68920373269686615887263401974106061570333027446036984502970074396634189398017',
      amount: '1',
      owner_of: '0xb82eee8676682176a18cf4642d5f1af8fd9149a9',
      token_hash: '6b76ddfb15a735cbfe2f26f5a7b5eb91',
      block_number_minted: '12152789',
      block_number: '15476409',
      contract_type: 'ERC1155',
      name: 'OpenSea Shared Storefront',
      symbol: 'OPENSTORE',
      token_uri: 'https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0x985f8c84655cadf4d245e2d075daa4ce8c0c4a930000000000003d0000000001',
      metadata: '{"name":"CryptoMinis #28","description":null,"external_link":null,"image":"https://lh3.googleusercontent.com/mUMarLE-1KI2tetVUFR3C_VY89X5oQkP4XKPdcSWD3yJMrwu0wPFfnk9TqK1QOBZKDD7wAjGfs4b4vMM8nW0_fQBXC4IBGzcoGNLbyc","animation_url":null}',
      last_token_uri_sync: '2022-06-27T19:25:28.155Z',
      last_metadata_sync: '2022-06-27T19:25:31.179Z'
    },
    {
      token_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
      token_id: '94322073105437744661048811618381034051372425087831030471219036179153071112292',
      amount: '1',
      owner_of: '0xb82eee8676682176a18cf4642d5f1af8fd9149a9',
      token_hash: '6d9c40533139ed7e2fb01fbef2f579ba',
      block_number_minted: '11918959',
      block_number: '15472054',
      contract_type: 'ERC1155',
      name: 'OpenSea Shared Storefront',
      symbol: 'OPENSTORE',
      token_uri: 'https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0xd08866c9153142c90ccd1d3105f751d060f138940000000000029a0000000064',
      metadata: '{"name":"Beeple No.21","description":"Edition of 100 priced on a bonding curve.\\n\\n73 editions burned on 3/4/21.","external_link":null,"image":"https://lh3.googleusercontent.com/77UtwsPyR_QH5OegMRB-FR9Ide7oG5PmlbZ_7EqkGikq8uBEdH6QcPJa45Cl64cIrciiExItrmv20k_b5ns0foiPpP0ZNiRFsUk-","animation_url":null}',
      last_token_uri_sync: '2022-08-08T19:04:00.083Z',
      last_metadata_sync: '2022-08-08T19:04:05.121Z'
    },
    {
      token_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
      token_id: '73881852512585366829397768378841787039894851789237845675354748636044371951617',
      amount: '1',
      owner_of: '0xb82eee8676682176a18cf4642d5f1af8fd9149a9',
      token_hash: '1bdc454a2959b3e3bc1cf41e8f998692',
      block_number_minted: '12337703',
      block_number: '15452180',
      contract_type: 'ERC1155',
      name: 'OpenSea Shared Storefront',
      symbol: 'OPENSTORE',
      token_uri: 'https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0xa357a589a37cf7b6edb31b707e8ed3219c8249ac000000000000c30000000001',
      metadata: '{"name":"CryptoModel #31","description":null,"external_link":null,"image":"https://lh3.googleusercontent.com/UnuUJIqQWSY-zI_ik4NWma-VcvJguRNLYzBKIWmI10HNDHhSMk5RCWufwE-HQfTe5F9G4CLI4rLZI7SxDTlRIUzcNwi1hEGNtUme","animation_url":null}',
      last_token_uri_sync: '2022-06-27T17:28:54.901Z',
      last_metadata_sync: '2022-06-27T17:28:58.130Z'
    },
    {
      token_address: '0x495f947276749ce646f68ac8c248420045cb7b5e',
      token_id: '68920373269686615887263401974106061570333027446036984502970074398833212653569',
      amount: '1',
      owner_of: '0xb82eee8676682176a18cf4642d5f1af8fd9149a9',
      token_hash: '1f423a03d00c5d464b050e702f4bfcd5',
      block_number_minted: '12152789',
      block_number: '15408435',
      contract_type: 'ERC1155',
      name: 'OpenSea Shared Storefront',
      symbol: 'OPENSTORE',
      token_uri: 'https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0x985f8c84655cadf4d245e2d075daa4ce8c0c4a930000000000003f0000000001',
      metadata: '{"name":"CryptoMinis #30","description":null,"external_link":null,"image":"https://lh3.googleusercontent.com/tAz7zJV4OhX5Ck8fwi_J6zSXWNK8K8xmdDFxeo6wzyE4FDT_mqHZoM0_1YwnQHUYFtSpyz2E8oZi3zigDPrMXiu4NB8ngVGG7xP0DeQ","animation_url":null}',
      last_token_uri_sync: '2022-06-27T17:50:52.891Z',
      last_metadata_sync: '2022-06-27T17:50:56.051Z'
    }
  ],
  status: 'SYNCED'
}

this is the value? this is where it tries to do that value.toUpperCase()?

Will need to go inside the module for logging that value

value.toUpperCase() is part of the error

Made the edit please check

ok, I think that I understand now what is the issue

1 Like

Thank you for the assistance, the issue seems persistent

you could filter the results by this token address if you want a quick fix, in case that you don’t want the first nft

We will need all the NFT’s and it’s metadata @cryptokid. The endpoint was working yesterday with the same nfts . Can you please confirm what went wrong ? I will patch it with your fix or something else till then .

what is seems to be wrong is that somehow first nft doesn’t have a contract type associated and it crashes when it tries to read the contract_type for that nft

alternatively you can read the raw data directly by making REST http requests to deep-index url as another possible work around, the data that you pasted above

you can try again now to see if it works

It’s working. Thank you

1 Like