Working with IPFS locally, did you hit the “no ‘Access-Control-Allow-Origin'” error?

So did I. 

If you’re doing decentralized application development, eventually you’re probably going to want to play around with the Inter Planetary File System (“IPFS”) because you simply can’t (and don’t want to) store too much data on the blockchain. 

My problem came up when I was doing some local development with a local node and a local React application.  I wanted to connect to the local instance of IPFS daemon using something like the following code from my React app (edited a little to simplify):

Of course, when I tried to run it, I hit the dreaded cross site security issue that CORS was developed to help with.  It’s pretty generic and not at all unique to IPFS.

Surprisingly, there isn’t too much written on the web on how to resolve this.  Simply disabling the browser’s security didn’t work because the IPFS local endpoint was configured to reject the cross-site request.

Long story short, all you have to do is change the local IPFS configuration. Start by editing your config file by using something like the following:

Now change the “API” section of the config file to look something like the following:

Restart your IPFS daemon and you should be good to go. 

Good luck out there and let me know how it goes for you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.