Lesson14: Doubt #1871
-
In BasicNft.sol function mintNft() public returns (uint256) {
_safeMint(msg.sender, s_tokenCounter);
s_tokenCounter = s_tokenCounter + 1;
return s_tokenCounter;
}
function getTokenCounter() public view returns (uint256) {
return s_tokenCounter;
}
const transectionResponse = await basicNFT.mintNFT()
const transectionRecipt = await transectionResponse.wait(1)
console.log(transectionRecipt) there is no |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
@adityabhattad2021 There is no solid reason I am seeing to return a counter from the mint function. We just need a unique id for it that we can give and leave the return statement. At that time I also did not notice that and I created my test like this: it("should mint an NFT and increment the token counter", async () => {
const tx = await basicNft.mintNFT();
await tx.wait(1);
const tokenCounts = await basicNft.getTokenCounts();
assert.equal(tokenCounts.toString(), "1");
}); |
Beta Was this translation helpful? Give feedback.
-
1. "Why is that we return s_tokenCounter when we have a getter function for it already, here"_safeMint(msg.sender, s_tokenCounter);
s_tokenCounter = s_tokenCounter + 1; Think of s_tokenCounter as an index. Let's assume the index is zero, so _safeMint mints with an index of zero and increments the index, and is now updated for the next execution, i.e. 1 and so on. So, to conveniently return the updated index rather than making conditionals—for the getter function—to check every time the index is updated. 2. "Now that as this mintNft() makes transection how can we get access to the s_tokenCounter; returned by it as when we try this"This seems correct to me, check if there are any other execution/code problems. |
Beta Was this translation helpful? Give feedback.
-
Created an Issue in the code repository PatrickAlphaC/hardhat-nft-fcc#14 regarding the same. |
Beta Was this translation helpful? Give feedback.
Created an Issue in the code repository PatrickAlphaC/hardhat-nft-fcc#14 regarding the same.