PatrickAlphaC/hardhat-nft-marketplace-fcc

Error: VM Exception while processing transaction: reverted with reason string 'ERC721: invalid token ID'

Furqan558 opened this issue · 4 comments

I got this error when I followed the course and create one test along with Patrick... and the issue was that, I was telling the test to read a tokenId = 0;
when the tokens Start at "1" ( or at least I think so )
So,
tokenId = 1;
solved the issue. Any thoughts on this?

even though Patrick ran the test with tokenId=0; ( and it worked )
So that is what I am actually confused about 🤔

sure!

I ran into the same issue here, but I figured out that in my case the cause of the issue is that after I copy and paste the contract BasicNft.sol from GitHub repo, I didn't notice that in the function mintNft, the s_tokenCounter incremented before calling _safeMint, so the solution to this issue is simply put that self-increment statement behind the _safeMint calling statement:
function mintNft() public { _safeMint(msg.sender, s_tokenCounter); s_tokenCounter = s_tokenCounter + 1; }