3

I get an exception when I call getBalance in Remix and the contract balance is greater than 0 (ie. I sent some ether using the fallback function):

Exception during execution. (invalid opcode). Please debug the transaction for more information.

When contract balance is 0 then getBalance correctly returns 0.

pragma solidity ^0.4.0;

contract Test {

    function() payable {}

    function getBalance() public constant returns(uint bal) {
        bal = this.balance;
        return bal;
    }

} 
2

There is no error in your code, I think after sending a transaction to your contract using the fallback function you call getbalance function with a non null value. While getbalance isn't a payable function you will get the mentioned error. So after before calling getbalance make sure that the value is 0 in remix transaction value :

enter image description here

  • indeed, I left the value there for every attempt. How embarrassing :) – szerte May 21 '17 at 14:08
0

I had similar problems. I think it is a browser cache problem. Try refreshing the page but first copy the contract address so you can watch it later by clicking "At address" button.

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.