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!

The Solidity “out of gas” error… you’re probably not really out of gas

This is my first week at OpenLaw, a Consensys spoke, where I get to not only do a little legal work as a legal engineer but also get to do some blockchain engineering, especially Solidity development.  I’m currently working on version 0.4.24.

But as you probably know if you dabble in Solidity, it’s still early days and a challenging platform compared to more mature languages! 

For example, for a few hours this afternoon I was absolutely flummoxed with the following error when running my Truffle tests:

So I diligently checked my Ganache settings and tried to change the gas settings on my Truffle transactions.  No dice. 

It turns out that this error is probably a red herring.  The more likely cause is that there’s an error in your deployment somewhere.  

It’s probably not a problem with your code (lightly speaking), or it Solidity wouldn’t compile.  However, it could be something that’s sorta, kinda related to your code.

In my case, everything was working until I tried to pull some contract names up into interfaces and had naming collisions even though I thought I had organized my code properly to avoid them.  Others have reported similar issues such as not implementing constructors from parent classes properly.

So, long story short, if you see the check-your-gas-amount “error” it’s probably not a gas issue — you probably have an issue lurking somewhere in your codebase.

Hope this saves you an hour or two….. good luck out there 🙂