Contract .call() question

I am having an issue in a for loop. the first day i tried it i was having trouble getting it to work, but the next time i got to work on it the error was gone and worked as i thought it should.

now its been a few days and i havent had much of an issue but now i got a 4th pet i get an error, is there a call limit?

lastAte = await contract.methods.getLastAte(petId).call();

works fine for the first 3 pets then it fails

Current user logged in as ui6DKnFrZj4WXFrkMxfwf1iJ
main99.js:165 20403353
main99.js:165 20434887
main99.js:165 20429309
inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: 'Internal JSON-RPC error.', data: {…}}

Maybe the 4th pet was not yet created/minted and that is why you get that error. It shouldn’t be any call limit in this case.

I got the food token that is minted with it and its in the database just fine.

is see in this print screen that you have pet ids: 1, 24, 33, 39. For which one of them it works and for which one it fails?

Current user logged in as ui6DKnFrZj4WXFrkMxfwf1iJ
main100.js:180 1
main100.js:180 24
main100.js:180 33
main100.js:180 39

all of them are there

I wanted to ask for which of them contract.methods.getLastAte(petId).call(); fails

Current user logged in as ui6DKnFrZj4WXFrkMxfwf1iJ
main100.js:180 Bober the Great
main100.js:181 1 petId
main100.js:183 20403353 lastAte
main100.js:180 2nd pet
main100.js:181 24 petId
main100.js:183 20434887 lastAte
main100.js:180 #3
main100.js:181 33 petId
main100.js:183 20429309 lastAte
main100.js:180 4th one
main100.js:181 39 petId
inpage.js:1 MetaMask - RPC Error

i got to head in to work, ill be back in about 9-10 hours

what do you have in solidity in that getLastAte function?

    function getLastAte(uint256 pet_id) external view returns (uint256) {
        //petUpdate(pet_id);
        return hogePets[pet_id].lastAte;
    } 
    
function createHogePet(address account, string memory name) public {
    //require(msg.sender == account, "Sender not authorized.");
    require(balanceOf(account, incuNFT) == 0, "Incu-Chamber already in use.");
    _tokenIds.increment();
    uint256 newId = _tokenIds.current();
    //HogePet(string name, uint256 favFood, uint256 index, bool canGrow, bool fed, bool hungry, uint256 lastGrown, uint256 lastAte, bytes32 blockBorn, address creator)
    hogePets.push(HogePet(name, newId, false, true, false, block.number, block.number, blockhash(block.number - 1), account, incuNFT, incuFood));
    _mint(account, incuNFT, 1, "");
    _mint(account, incuFood, 1, "");
    emit newPet(name, newId, account, blockhash(block.number - 1));

}

that might be it, i didn’t call the struct pet_id but the local variable in the function is emited

You may always have problems with the last one, if hogePets is an array and if it is zero indexed then the index from that array may not be identical with the newId that may start from 1

it was working fine for a week or so now. but yesterday i updated the front end and got my 4th one. i had a thought early on that it may at some point become misaligned, but i thought i had that covered.

Ill be looking more in to it when i get home in about 8-9 hours

its working now, no code changes, maybe network issues idk

strange, you still have only 4 NFTs or you minted a new one meanwhile?

came home from work and it was the .call() worked fine.