I am trying to use the getWalletTokenIdTransfers in NodeJS to get all of the transactions of 1155 tokens to see what address have staked their NFTs. I had code for this that had been working but it came to my attention last week that my code was no longer functioning. The error being given each time is “Error: Invalid cursor”. I have had success with this code using cursors before and this error occurred without me doing any updates to the code packages. With the offset option removed I tried using the .next() method instead and got the same result.
I looked at the “Example of how to use cursor (nodejs)” page and adapted it to the code below that generates the same error.
I would appreciate any help with figuring out what is going on.
console.log("Starting");
await Moralis.start({ moralisServerUrl, moralisAppId, moralisSecret });
console.log("Started");
const contractAddress = "0x38a6fd7148c4900338e903258B5E289Dfa995E2E";
async function getAllOwners() {
let cursor = null;
let owners = {};
do {
//const response = await Moralis.Web3API.token.getNFTOwners({
const response = await Moralis.Web3API.token.getWalletTokenIdTransfers({
address: contractAddress,
chain: "eth",
limit: 100,
cursor: cursor,
token_id: 1
});
console.log(
`Got page ${response.page} of ${Math.ceil(
response.total / response.page_size
)}, ${response.total} total`
);
for (const transaction of response.result) {
transaction[transaction.transaction_hash] = {
from: transaction.from_address,
to: transaction.to_address,
};
}
cursor = response.cursor;
} while (cursor != "" && cursor != null);
console.log("owners:", owners, "total owners:", Object.keys(owners).length);
}
getAllOwners();