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();