PatrickAlphaC / hardhat-nft-marketplace-fcc

114 stars 97 forks source link

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

Closed Furqan558 closed 2 years ago

Furqan558 commented 2 years ago

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?

Furqan558 commented 2 years ago

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

PatrickAlphaC commented 2 years ago

Can you:

  1. Make this a discusson on the full repo? https://github.com/smartcontractkit/full-blockchain-solidity-course-js/
  2. Follow this section for formatting questions? https://www.youtube.com/watch?t=19846&v=gyMwXuJrbJQ&feature=youtu.be
Furqan558 commented 2 years ago

sure!

MyNameIsTakenOMG commented 2 years ago

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; }