Replies: 1 comment
-
|
Dear @creulean, Thank you for trying out our NFT tutorial and for reaching out. You are absolutely right—the However, your code differs from what is written in the Soneium documentation. You can find the official code here. Specifically, the /// @dev the function can be called by anyone
function safeMint(address to) public {
uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
}This means the erroneous line in your code is not present in our documentation. Could it be that you copied it from another source? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Today I deployed the NFT according to the tutorial in Soneium's documentation. I only changed the name of the NFT, and a problem occurred.
My code looks like this:
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;
After running the command
npx hardhat test --network hardhat, the following issue occurred:The issue with the code is the missing return value declaration for the
safeMintfunction. So I removed the return value and it ran successfully. The code is:or
function safeMint(address to) public returns (uint256) { // ✅ Declare return uint256
uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
return tokenId; // ✅ return tokenId
}
After running
npx hardhat test --network hardhatagain, return:I don't know why I have this problem, but after using the two solutions above, the error disappeared.
I'm not sure if my modifications will affect the subsequent code. I hope you can give me some guidance on why this problem occurred and whether my issue can be resolved this way.
Beta Was this translation helpful? Give feedback.
All reactions