Solidity/Remix Error – Why Am I Getting a “Error: Invalid Address” in Solidity/Remix?

remixsolidity

When I call the "setStartTime" function, it works but when I check "_startingTime" I get this error:

call to timeTracker._startingTime errored: Error encoding arguments: Error: invalid address (argument="address", value="", code=INVALID_ARGUMENT, version=address/5.1.0) (argument=null, value="", code=INVALID_ARGUMENT, version=abi/5.1.2)

Why am I getting this? If I am able to set time, then the mapping should have something to return?


contract timeTracker {

    mapping(address => uint256) public _startingTime;
    uint256 constant ONE_DAY = 86400;

    function setStartTime() public returns (uint time) {

        _startingTime[msg.sender] = block.timestamp;
        return _startingTime[msg.sender];
    }

    //checks if 24 hours have passed
    function checkIfDayPassed() public {
         //86400 seconds in a day
        require(block.timestamp - _startingTime[msg.sender] >= ONE_DAY, "Claim not ready");
  _startingTime[msg.sender] = block.timestamp;
    }
    
}

Best Answer

In your code above, _startingTime is defined as a mapping. When calling it, you need to pass it a correctly formatted address as an input for it to return anything meaningful. Apparently, you were calling it without passing in any value.

Related Topic