0

Similar code to this works in other contracts, but not this one. I'm getting a gas error: "errored: Error: gas required exceeds allowance or always failing transaction".

I've narrowed it down to the line causing the problem. What is wrong with this call, and is there any way to get a more descriptive error?

contract GuessTheRandomNumberChallenge {
    uint8 answer;

    function GuessTheRandomNumberChallenge() public payable {
        require(msg.value == 1 ether);
    }

    function guess(uint8 n) public payable {
        require(msg.value == 1 ether);

        //do stuff
    }
}

GuessTheRandomNumberChallenge public handle;

constructor() public payable {
    handle = GuessTheRandomNumberChallenge(0x123123mycontractaddress);
}

function check() public {
    handle.guess.value(1 ether)(83); //PROBLEM LINE
}

1 Answer 1

1

Possible issues I can think of:

  • Insufficient balance in the contract to send the 1 ether.
  • The address you provided for the handle is wrong
  • Ether is sent to an unpayable fallback

For getting more info, I would suggest using the Remix debugger, and playing around with the contracts in the js-vm.

2
  • The insufficient balance idea got me thinking. The problem ended up being the contract sent back ether, and the fallback function wasn't payable. Thanks for your help.
    – toast
    Commented May 23, 2018 at 2:10
  • 1
    Cool, thanks for accepting the answer. I added that case.
    – maurelian
    Commented May 24, 2018 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.