I created an ERC721 contract and deploy it on the Goerli testnet.
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TestNFT is ERC721URIStorage, Ownable {
uint256 totalMinted = 0;
constructor() ERC721("MyNFT", "MNFT") {}
function mint(address to) public {
_mint(to, totalMinted);
totalMinted++;
}
function mintWithData(address to, string memory tokenURI) public {
_mint(to, totalMinted);
_setTokenURI(totalMinted, tokenURI);
totalMinted++;
}
function setTokenURI(uint256 tokenId, string memory tokenURI)
public
onlyOwner
{
_setTokenURI(tokenId, tokenURI);
}
}
It has 3 functions mint
, mintWithData
and setTokenURI
. Opensea can just show NFT with the function mintWithData
. This function have 2 function _mint
and _setTokennURI
.
I manually minted NFT and set token URI with 2 functions mint
and setTokenURI
. But it just shows an NFT without any metadata.
Can anyone tell me why this occurs? I used the same function with mintWithData
but it can't work.