In something like this, how can I tell which require the contract exits on?

pragma solidity ^0.4.19;

contract Demo {
    uint _a;
    function Demo(uint a) public {
        _a = a;

    function demo() public view {
        require(_a == 1);
        require(_a == 2);

All that's logged in the console is:

[call] from:0xca35b7d915458ef540ade6068dfe2f44e8fa733c, to:Demo.demo(), data:01725...25a0b, return: 
 from   0xca35b7d915458ef540ade6068dfe2f44e8fa733c
 to     Demo.demo() 0xcd021ffd464dc40614c4dd7e7826b3d91a21ab12
 transaction cost   21854 gas (Cost only applies when called by a contract)
 execution cost     582 gas (Cost only applies when called by a contract)
 input  01725a0b
 decoded input  {}
 decoded output     {}
 logs   []
call to Demo.demo errored: VM error: revert.
revert  The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value.  Debug the transaction to get more information. 
creation of Demo pending...

I believe that, as suggested, debugging the transaction in Remix is the best available option. I don't find Remix's debugger to be that great, but it does allow you to step through the function. It won't let you step past the require that failed, so you can see where the revert happened.

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.