I have a bunch of JSON files in a directory that I'm uploading to IPFS, to be used as NFT metadata. The problem is that after I upload them, the URI to access them looks like this: ipfs://<directory_hash>/<tokenID>.json.

This is a problem because the tokenURI function in the standard ERC721 implementation simply appends the token ID to baseURI. This means each token's URI would have to look like this: ipfs://<directory_hash>/<tokenID>, without the .json file extension.

I know I could just override this function or simply edit it, but I'd rather not. Especially because I've seen other NFT projects successfully do what I'm trying to do but can't seem to figure out.

So, when uploading JSON files in a directory to IPFS, how can I prevent the .json extension from being part of the URI?

  • How did you manage to create directories in IPFS?!
    – PedroD
    Nov 9 at 20:28

I would suggest simply removing the .json extension from the files and uploading them to ipfs like that. They will function all the same, but will the URIs will then resolve correctly

  • 1
    Stupid question, but how would I do this exactly? I'm on MacOS. If I rename the files in Finder, they still show up with the .json extension in terminal. If I rename them and remove the extension with mv then they are converted to text files. Aug 28 at 22:56
  • 1
    Never mind I figured it out... For some reason it didn't occur to me that JSON files were interchangeable with text files :/ Aug 30 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.