[SOLVED] MoralisError [Moralis SDK Core Error]: [C0005] Invalid address provided

I’m attempting to loop over an array of addresses to call getWalletTokenTransfers against and am getting an [C0005] Invalid address provided error.

When testing with the address I used before implementing any arrays, loops, or streams I’m still getting the same error which is very confusing especially considering the web call on https://docs.moralis.io/reference/getwallettokentransfers works with it.

Below is my code with sensitive variables replaced with all caps:

const Moralis = require("moralis").default;
const EvmChain = require("@moralisweb3/evm-utils");
const { stringify } = require("csv-stringify");
const fs = require("fs");
const { parse } = require("csv-parse");
const { resolve } = require("path");

async function apiPull() {
  let count = 0;
  const chain = EvmChain.ETHEREUM;
  const address = [];

  await Moralis.start({
    apiKey: "APIKEY",
    logLevel: "verbose",
  });

  console.log("Moralis started");

  function createReadStream() {
    return new Promise((resolve) => {
        fs.createReadStream("./FILENAME.csv")
        .pipe(parse({ delimiter: ",", from_line: 1 }))
        .on("data", function (row) {
          address.push(row[0]);
        })
        .on("end", function () {
          console.log("finished");
          resolve(address);
        })
        .on("error", function (error) {
          console.log(error.message);
        });
    });
  }

  const finalData = await createReadStream();

  for (let i = 0; i < address.length; i++) {

    let addressi = address[i].toString();
    console.log("AddressI: ", addressi);
    let addressx = 'WALLET ADDRESS';
    console.log("AddressX: ", addressx);

    const response = await Moralis.EvmApi.token.getWalletTokenTransfers({
      addressx,
      chain,
    });
    console.log(i);

    console.log("TRANSACTIONS: ", response.data.total);

    //write response to file
    respString = JSON.stringify(response.data.total);

    try {
      fs.writeFileSync(`FILENAME.csv`, respString, { flag: "a+" });
      console.log("Count: ", count);
    } catch (err) {
      console.error(err);
    }
  }
}

apiPull();

const response = await Moralis.EvmApi.token.getWalletTokenTransfers({
addressx,
chain,
});

This needs to be:

const response = await Moralis.EvmApi.token.getWalletTokenTransfers({
      address: addressx,
      chain,
});

You’re trying to use addressx as a property, this function expects address.

Ok thanks that worked, but is confusing because the documentation doesn’t specify that and actually shows the variable alone:

Below code directly from https://docs.moralis.io/reference/getwallettokentransfers

import Moralis  from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';

const address = '0x1234567890123456789012345678901234567890';

const chain = EvmChain.ETHEREUM;

await Moralis.start({
    apiKey: '<YOUR_API_KEY>',
    // ...and any other configuration
});

const response = await Moralis.EvmApi.token.getWalletTokenTransfers({
    address,
    chain,
});
console.log(response.result);

here the variable already has that specific name, it will work if you keep the name, if you change the name it will not work any more