[SOLVED] Error with getWaletNFTs

Hi,
I am using moralis in a next.js environment and i have updated the moralis package to the latest version.

When i query getWalletNFTs i get the same number of results (34) wether i specify the token_addresses parameter or not. The correct answer should be 2 with token_addresses set and 34 when it is not specified.

                  const Address = '0x??????????????';
                  const chain = EvmChain.ETHEREUM;
                  const smartContract = '0x06012c8cf97bead5deae237070f9587f8e7a266d';

                  const response = await Moralis.EvmApi.nft.getWalletNFTs({
                    address: address,
                    chain: chain,
                    token_addresses: smartContract,
                  });

What am I doing wrong?

The output shows 34 objects and the first one is the voyager connected to the address, although it clearly states token_addresses and the cryptokitties contract.

ApiPaginatedResultAdapter {
  data: {
    total: 34,
    page: 1,
    page_size: 100,
    cursor: null,
    result: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object]
    ],
    status: 'SYNCED'
  },
  adapter: [Function: apiToResult],
  jsonAdapter: [Function: resultToJson],
  params: {
    address: '0xC?????????????????????????',
    chain: EvmChain {
      config: [Config],
      _value: '0x1',
      _chainlistData: [Object]
    },
    token_addresses: '0x06012c8cf97bead5deae237070f9587f8e7a266d'
  },
  nextHandler: undefined,
  hasNext: [Function (anonymous)],
  next: [Function (anonymous)]
}

First part of the response.data including the contract of the first object. Which is a Voyager Unknown NFT, and its definately not the cryptokitties contract address.

{
  total: 34,
  page: 1,
  page_size: 100,
  cursor: null,
  result: [
    {
      token_address: '0xdeadab7c1324c0614e1512e3034bddd44f7fface',
      token_id: '????',

Happy for any help.

If you are using the latest moralis version (2.4.0), try tokenAddresses, which needs to be an array of strings (token_addresses is an array of strings).

const smartContract = ['0x06012c8cf97bead5deae237070f9587f8e7a266d'];

const response = await Moralis.EvmApi.nft.getWalletNFTs({
    address: address,
    chain: chain,
    tokenAddresses: smartContract,
});

Hi glad, thank you for your reply, but i still get all NFTs for that address not only those for the cryptokitties contract (0x06012c8cf97bead5deae237070f9587f8e7a266d).

I double checked the version and it is 2.4.0.

I changed the smartContract variable to an array as per your instructions.
However, the output stays the same. Apart from tokenAdresses showing the contract address as part of an array now.

My code:

                  const Address = '0xC?????????????';
                  const chain = EvmChain.ETHEREUM;
                  const smartContract = ['0x06012c8cf97bead5deae237070f9587f8e7a266d'];

                  const response = await Moralis.EvmApi.nft.getWalletNFTs({
                    address: address,
                    chain: chain,
                    token_addresses: smartContract,
                  });
                  console.log(response);

response (correct answer is 2):

ApiPaginatedResultAdapter {
  data: {
    total: 34,
    page: 1,
    page_size: 100,
    cursor: null,
    result: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object]
    ],
    status: 'SYNCED'
  },
  adapter: [Function: apiToResult],
  jsonAdapter: [Function: resultToJson],
  params: {
    address: '0xC??????????????????????',
    chain: EvmChain {
      config: [Config],
      _value: '0x1',
      _chainlistData: [Object]
    },
    token_addresses: [ '0x06012c8cf97bead5deae237070f9587f8e7a266d' ]
  },
  nextHandler: undefined,
  hasNext: [Function (anonymous)],
  next: [Function (anonymous)]
}

My code:
token_addresses

Did you use tokenAddresses like in the code I posted (not token_addresses but this is still the general parameter name, apologies for any confusion)? It needs to be exactly like that for the latest SDK version.

Ahh, off course i did not ;(

That was the problemโ€ฆ now it works.

However you should fix the variable name on: https://docs.moralis.io/reference/getwalletnfts where it says token_addresses.

Thanx a lot for the help, I really appreciate it.

Best
//Deb

tokenAddresses is only for latest SDK usage - itโ€™s still token_addresses for direct API usage or other SDKs. I understand the confusion.