I have the code below inside a contract, whenever I run the function getTimeUntilRewrdClaimable it works until the time is under zero.. If the time is under zero it throws this error...
VM error: revert.
revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you
send should be less than your current balance.
Debug the transaction to get more information.
My Code inside my contract:
mapping( uint256 => ObjectDetails) private attributes;
// Object Structure...
struct ObjectDetails {
uint dailyClaim;
uint lastClaimDate;
}
function getTimeUntilRewrdClaimable(uint256 tokenId) public view returns (int) {
return int(attributes[tokenId].lastClaimDate + 60 - block.timestamp);
}
Thanks to any and all feedback!
attributes[tokenId].lastClaimDate
is a uint, so attributes[tokenId].lastClaimDate + 60 - block.timestamp
is as well. This causes an issue when attributes[tokenId].lastClaimDate + 60
is less than block.timestamp
. To fix, cast both parts to int before doing the subtraction:
return int(attributes[tokenId].lastClaimDate + 60) - int(block.timestamp);