3

I'm attempting to get the JSON object from a known IPFS link. When I use a function like $.getJSON() or node-fetch I am greeted with an error telling me I can only use HTTP. I've searched around for hours now and found nothing on this.

Example IPFS link: ipfs://bafybeignop35wemk2eu2z34qurwusjeuri6unpyzrzeetmxs4hrwksq7dq/?filename=tokenURI.json

TylerH
  • 20,799
  • 66
  • 75
  • 101
jjreedv
  • 71
  • 2
  • 7

1 Answers1

4

That function will not work through the IPFS protocol ipfs://. The quickest and dirtiest way to get that JSON file is to use a trusted public gateway.

You'll find the list of public gateways via the link below.
https://ipfs.github.io/public-gateway-checker/

The most important bit of information in that link is your CID that might refer to a folder or a single file. You can link to your JSON file with that CID using any of these public gateways.

e.g.; https://ipfs.io/ipfs/bafybeignop35wemk2eu2z34qurwusjeuri6unpyzrzeetmxs4hrwksq7dq/?filename=tokenURI.json

Please note that these gateways are not there to use in any production environment. They usually come with restrictions such as rate-limiting.

You can read more here:
https://docs.ipfs.io/concepts/ipfs-gateway/#can-websites-rely-on-the-ipfs-io-gateway-for-hosting

I also recommend you this article they have, you'll better understand the whole concept.
https://docs.ipfs.io/concepts/ipfs-gateway/#gateway-providers

rolandsaven
  • 143
  • 2
  • 9
  • This was helpful. Not easy to find examples like this. Thank you for the LINKS. Would also like to see examples of: convert IPFS to JSON from within REMIX: Solidity. – Nash Worth Oct 18 '22 at 20:49