Getting a negative token id when buying nft

Hello,
I am facing an issue when I buy a nft through the Shop which I created by following the steps mentioned in the official tutorial by Moralis Web3 channel on youtube. I am getting a negative token ID, is this a bug or is this a functionality by Morlais? Please explain.

Youtube Tutorial

Which contract address (and chain) are you using? What does the tokenId look like and what does your function call (buyItem) look like?

Hello,
My contract address is : 0x4cec0a85A8F8CAe8c340E59Ae1a91Ef0300F6047
Chain : Mumbai
buy Item function : function buyItem(uint256 _tokenId, string memory _tokenUrl, bytes memory data) public /onlyOwner/{

    //IMPORTANT Implement own security (set ownership to users). Not production ready contract
    
    _tokenUrls[_tokenId] = _tokenUrl;
    _mint(msg.sender, _tokenId, 1, data);
}

I am getting token ID : -21, -11, 11, etc. also I am getting same token ID for some items.

I have not made any changes to the buyItem function.
What is the problem here?
Please help!!!

Everything seems ok with that contractโ€™s events with tokenIds of 235 and 11 used. Can you screenshot these negative tokenIds youโ€™re getting - it may be an issue with the Unity project.

Make sure your code matches the tutorial repo and any changes made in the video.

1 Like