I'm writing a contract using remix, and I'm hitting an error but I can't debug it. When I enter the transaction hash in remix it tells me the json is empty ("").

I'm testing on the ropsten test network and using metamask for may wallet.

Is there a way I can log text and view those logs?


A failed transaction cannot emit an event, because failed == nothing happened. This is inconvenient for debugging.

You can check assumptions with require() and emit a reason. Reasons are observable when the require() expression evaluates to false.

There are many reasons why a contract can fail. Some are deliberately caught and emit a reason but others are because of protocol or because further processing isn't possible.

A protocol-level error would be sending more money than the account actually has. You would check on your own that such is not the case. Nothing you can do in the contract to make it more informative because it won't get that far.

Further processing is not possible on divide by zero, accessing an array out of bounds, etc., and those things can be checked with require().

For example:

function elementAtIndex(uint row) external view returns(address) {
  require(row < myAddressArray.length, "row is out of range");
  return myAddressArray[row];

or ...

function divider(uint nom, uint denom) extern pure returns(uint) {
  require(denom > 0, "denominator is zero");
  return nom/demon;

As a general heuristic, try to deliberately catch every error that can possibly occur. You can often report what the problem is, and if you get no message, at least you know what the problem isn't. When you optimize, remove checks for impossible conditions that you might have inserted for debugging purposes, but incline to keeping the informative messages for possible situations related to input since it helps everyone understand what's going on.

Hope it helps.

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.