[code]
interface ERC721Metadata /* is ERC721 */ {
/// @notice A descriptive name for a collection of NFTs in this contract
function name() external view returns (string _name);
/// @notice An abbreviated name for NFTs in this contract
function symbol() external view returns (string _symbol);
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
function tokenURI(uint256 _tokenId) external view returns (string);
}
{
"title": "Asset Metadata",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Identifies the asset to which this NFT represents"
},
"description": {
"type": "string",
"description": "Describes the asset to which this NFT represents"
},
"image": {
"type": "string",
"description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
}
}
}
[/code]
I am now beginning to think that what I am trying to do is not possible with an ERC721.
It looks like I will have to create a separate .json metadata file for each NFT and wrap them into an IPFS folder.
I was hoping to create one .json metadata file as shown in my previous post and looking up the contents of the array within that by appending to token uri to a base URI to create some form of URL which would pull out the metadata for each NFT by using its token id as each token is minted.
Again thanks for your support and any further help would be greatly appreciated.
You're correct that ERC721URIStorage concatenates the base URI with the token URI.
If I'm understanding your issue correctly, I think the problem you're running into here stems from the challenge of forming a URL that links to a specific section of a single .json file. Accessing a given array within a single .json object is straightforward if you're using Javascript but I'm not sure that there is the equivalent to HTML anchor tags in IPFS for linking directly to arrays within .json files.
If it were me, I would probably stick with the standard implementation and split my data into separate .json files.
I agree that does seem the best possible route for this and thanks for confirming the conclusion I was coming to. I just didn't want to miss out on trick if there had of been one available.
Having one single json file is your issue.
The URI will point to a file. And that file will be loaded. There is no active script in the process to target one specific id within that file.
You need a folder that contain many file
folder/0.json
folder/1.json
Each file contain the metadata for a single NFT.
Once you have all your file in a folder. You upload this folder to IPFS.
Then this hash become your base URI.
so when you fetch an id you get the data for that NFT only.
Did you solve the issue? I am on the same point with a master practise.
I think the trick is modify this function:
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}