the thing is that i have a very simple contract code that I wrote as a kind of "Hello World!", but it doesn't seem to work properly, and I can't see any reason why it wouldn't work.

The code I'm talking about is this one:

pragma solidity >0.4.18;

contract TimedSafe {

    address creator;
    address bank = 0xB599C8008E505ed9bd34C4761EBAae53a89207Af;

    uint256 safe;

    uint256 startTime;
    uint256 endTime;

    uint8 state; 

    /* Constructor */
    constructor() public {
        creator = msg.sender;
        state = 0;

    function storeSafe(uint8 m) public payable {
        assert(msg.sender == creator);
        assert(state == 0);
        safe = msg.value;
        startTime = now;
        endTime = startTime + (m * 1 minutes);
        state = 1;

    function retrieveSafe() public {
        assert(msg.sender == creator);
        assert(state == 1);
        if(now < endTime) {
            state = 2;
        } else {
            state = 3;

    function timeLeft() public view returns (uint256 t) {
        assert(state == 1);
        return endTime - now;

    function getState() public view returns (uint8 st) {
        return state;

The function that doesn't work properly is "retrieveSafe". I deployed this contract on the Ropsten testnet, just in case it is of importance.

  • If you can share a link to the failed transaction on Ropsten, it's likely possible for someone to tell you exactly what went wrong. Otherwise we just have to speculate as to which of the requires or transfers is failing. – user19510 Apr 8 at 18:15
  • @smarx Of course, here it is: ropsten.etherscan.io/tx/… – Victor Dorado Apr 8 at 18:26
  • The input data for that transaction is just 0x, so you didn't call any function. How are you attempting to call retrieveSafe? Are you using a tool? If so, what? Are you writing code? If so, please share the code. – user19510 Apr 8 at 18:31
  • @smarx The only code I wrote is posted here. And about the 0x input, I don't really know why it's like that, I'm only using the Mist wallet tool for calling functions on the contracts, and it does "everything" by itself. – Victor Dorado Apr 8 at 18:38
  • It's been a long time since I've used Mist for anything, but it would seem there's a bug there. I can tell you with confidence that the transaction you sent is not calling retrieveSafe and is instead just invoking the function's fallback function (which doesn't exist and therefore reverts). Either figure out how to get Mist to send a valid transaction or switch to another tool. – user19510 Apr 8 at 18:40

The transaction in question has input data of 0x, so it is not a call to safeRetrieve or any other function implemented in the contract.

When a transaction comes into a contract that doesn't match an existing function, the fallback function is invoked instead. In the case of a missing fallback function, as is the case here, the transaction is reverted.

Per the comments on the original question, this appears to be some sort of issue in Mist. Calling the function via Etherscan and MetaMask worked.


It's impossible to say for sure which part is problematic. As your function call is throwing the cause is most likely either of the function's two first lines which are checking for conditions with require. So either of those require statements throws.

One way to find out which one causes problems is to comment out the require statements one by one and see when it stops throwing errors.

You should also use a newer version of Solidity - the newest version is 0.5.7 (https://github.com/ethereum/solidity/releases) and you may be using something as old as 0.4.18. The language evolves rapidly and newer version is typically better.

  • I just tried and deployed another version of the contract but with both assert commented, and the result is the same: failed. The transaction with the new code is this one: ropsten.etherscan.io/tx/… . My guess is that the problem is with transfer, because remix also tells that the gast cost of retrieveSafe is high, potentially infinite. – Victor Dorado Apr 8 at 18:39
  • Ah, read what smarx told you. – Lauri Peltonen Apr 8 at 18:41

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.