Using a base uri with token id to access metadata


I am trying set up an erc721 to access metadata so I can use the same .json file for multiple NFTs.

I have created my .json metadata file link

I'm using a .json host for testing but proposing to move it IPFS if I can get it working.

I have added a "/" to the end of my to set my base uri to so that when it concatenates with token id it should give for example for say token id = 0.

Doing this doesn't read the data for the token from .json file.

I looked on loads of threads and websites but can't see what I am doing wrong as I am not a very experienced programmer.

Any help would be greatly appreciated.


You would have to show that part of the code specifically for anyone to help.

Your string should probably have 64 zeros prefixed to ".json"



Hi Matt,

Thanks for your reply.

Here is a copy of the code for the .json file and the erc721.



Again any help would be greatly appreciated.


Hello Rob

Have checked the standard ?

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."

Also if you search around these forums there are quite a few posts regarding this.

I've been using the ERC1155 and I have not deployed an ERC721

However if your still stuck on this later. I will come and figure it out with you.

If will be something or nothing.

Thanks Matt for your support.

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.

All the best


1 Like

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.

1 Like

Thanks iink for your reply.

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.

Also thanks Matt for your input also.

All the best

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

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.


1 Like