[Ethereum] How to debug solidity contracts with truffle

contract-debuggingsolidity

I've been having a very hard time with Solidity development due to not being able to easily console log as well as the truffle debugger causing problems.

How do you console log in Solidity?

Truffle debug doesn't seem to work very well when you've used inheritance.
When a function throws an exception the event logs don't help correct?
What is the easiest way to listen for event logs using a tool like Ganache or Truffle?

Best Answer

You can't really console log with solidity, and truffle sometimes won't help much about understanding where your code fails.

Truffle indicates somes issues and warnings (like unused declared vars) but, as you mentionned, when using inheritance it can be a pain.

An easy way to deal with this, the one i use, is to load or copy/paste the .sol files into the remix IDE and check what are the issues it shows.

Once done and issues fixed i move my fixed code into the relevant files.

Note that you can download Remix IDE and create your own instance of it here

It might not be the perfect solution but awaiting for truffle to provide more information when having some issues, remix IDE is a very good tool for debugging. On my side i use truffle only for compiling and rely on the IDE for debugging.

Related Topic