I am trying to create a simple ERC721 contract that mints a NFT hard coded into the contract to anyone who sends 100 Wei.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "https://github.com/nibbstack/erc721/blob/master/src/contracts/tokens/nf-token-metadata.sol";
contract myNFT is NFTokenMetadata {
uint tokenId = 0;
string[] nfts = ["https://ipfs.io/ipfs/bafybeibnsoufr2renqzsh347nrx54wcubt5lgkeivez63xvivplfwhtpym/metadata.json"];
function mint() public payable {
require(msg.value == 100, "Send 100 Wei");
super._mint(msg.sender, tokenId);
super._setTokenUri(tokenId, nfts[0]);
tokenId++;
}
}
The metadata JSON looks like this:
{"name":"No time to explain!","description":"I said there was no time to explain, and I stand by that.","image":"ipfs://bafybeidfjqmasnpu6z7gvn7l6wthdcyzxh5uystkky3xvutddbapchbopi/no-time-to-explain.jpeg"}
This metadata JSON works if I pass this uri as an argument through a standard minting call (_to, _tokenId, _uri), but it doesn't work in the above contract and I don't know what's wrong.
I deployed the contract on the Goerli Testnet, but the image is not visible on opensea testnet:
contract: https://goerli.etherscan.io/address/0x6b9c84cb4f900d74b02854fdf8666abf5f68d457
opensea: https://testnets.opensea.io/collection/unidentified-contract-snzheyndyi
OpenSea sometimes can't load the NFT metadata instantly I refreshed your metadata now image is also seenable. Check here.
Also instead;
string[] nfts = ["https://ipfs.io/ipfs/bafybeibnsoufr2renqzsh347nrx54wcubt5lgkeivez63xvivplfwhtpym/metadata.json"];
Using;
string[] nfts = ["ipfs://bafybeibnsoufr2renqzsh347nrx54wcubt5lgkeivez63xvivplfwhtpym/metadata.json"];
Can be better since it is already stored in blockchain.
Because, in case of https://ipfs.io goes down your NFT's metadata won't be accessible.