I am experiencing a weird issue. I am building a DApp where I want the new season of the game to start every 5 minutes (for testing purposes). However, web3 call returns old data, seems that it cached it and didn't refresh unless I send a tx. Here is a code snippet, smart contract:
uint public constant SEASON_DURATION = 5 minutes;
uint public start;
constructor() public {
start = now;
}
function getCurrentSeason() public view returns (uint) {
return (uint) ((now - start) / SEASON_DURATION);
}
React frontend:
const season = await myContract.methods.getCurrentSeason().call({from: activeAccount});
After 5 minutes pass, it still returns 0 even if I refresh the page. If I do a transaction (invoke any function in a smart contract), then getCurrentSeason() returns the correct value. What could be the solution?
I am using:
- web3 ^1.2.6
- Solidity v0.5.16
- Ganache (GUI version) v2.1.2
- Truffle v5.1.9
- Node v10.15.3
- Metamask wallet