3

Problem The transaction fails because the transaction ran out of gas instead of it failing because the require condition was not met. It works fine before the solidity update to version 0.4.24. It works in all environment. It can even return the reason I provided with the error in the require parameter. Why is it saying that the gas is not enough? I've tried to assign a higher gas limit, higher than 3000000. I am using remix.ide

Note Everything works fine if I don't make the require onlyOwner modifier to result to an error.

Expected result Error with provided reason Contract Code

pragma solidity ^0.4.24;

 contract Owned {
 address public owner;
 address public newOwner;

 event OwnershipTransferred(address indexed _from, address indexed _to);

 constructor() public {
     owner = msg.sender;
 }

 modifier onlyOwner {
     require(msg.sender == owner);
     _;
 }

 function transferOwnership(address _newOwner) public onlyOwner {
     newOwner = _newOwner;
 }

 function acceptOwnership() public {
     require(msg.sender == newOwner);
     emit OwnershipTransferred(owner, newOwner);
     owner = newOwner;
     newOwner = address(0);
 }
}

Using JavaScript VM Environment expected result even on Injected Web3 and Web3 Provider Environment

-The image above is the result I expect to get when I use the Injected Web3 and Web3 Provider Environment as that is how it works before around the solidity version 0.4.23.

Using Injected Web3 and Web3 Provider Environment Occurs upon execution of transferOwnership()

--The window on the above image will pop-up upon execution of the transferOwnership() function. The function with the onlyOwner modifier which require the msg.sender to be equal to the contract owner.

After I force execute the transaction of transferOwnership()

--The image is the result when I choose to still proceed with the transaction even after the warning from the 2nd Image. It results to the same "Transaction mined but execution failed" status like when I ran it using the JavaScriptVM Environment but without the "VM error: revert." return.

0

@vhie I tried you code and works fine on Remix, I think the problem is that you are selecting the wrong account for each operation so it triggers the require and do a revert.

You have to make sure that you are selecting the newOwner address for the acceptOwnership() function and the owner address on the transferOwnership() function.

If I select the wrong address in either of these functions I get the same error as you.

  • Hi, I'm sorry but that is exactly my problem. The gas error when I trigger the require condition. I will edit my question to note this. It is not suppose to return that error. Like I said above it is suppose to return the same error as the one in Image 1 or 2. If I execute the function correctly meaning not triggering the require condition to revert it works fine. The problem it when I do trigger the require function to error and revert. Thank you – vhie Jul 5 '18 at 1:37
  • I see @vhie sorry I didn't understand your question. Apparently this was added to remix but for some reason is not displaying it anymore. github.com/ethereum/remix/pull/760 maybe you can open a issue. – Olivers De Abreu Jul 5 '18 at 16:51
  • I see, Thank you for the information. Could this be the reason why it only works in the JavaScript VM Environment and not in Web3 Provider or Injected Web3 Environment? – vhie Jul 6 '18 at 1:29
  • Hi, this pull request github.com/ethereum/remix/pull/760 add the ability to display the reason of the REVERT for the JavaScript VM. It is not possible for now to display the REVERT reason for other environment. – Yann Jul 6 '18 at 9:50
  • For me, I had the wrong contract address that I was connecting to. – Kirby Nov 4 '18 at 23:08

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.