Ethereum Asked on November 24, 2021
I am trying to push data to an address array within a struct array. There are no errors, however, when I check the storage of the array in my contract in Ganache, it remains empty. Is there something wrong with my code? Or is it not meant to display in Ganache? And if the data doesn’t display in Ganache, does that mean it isn’t being stored anywhere?
My code is provided below. I am trying to push data to the address array challengers in struct array challenges through function acceptChallenge.
pragma solidity >=0.5.0 <0.6.0;
contract GameChanger {
uint ChallengeCount = 0;
struct Challenge {
string name;
address host;
string description;
uint starttime;
uint timelimit;
uint reward;
uint challengercount;
address[] challengers;
}
Challenge[] public challenges;
function createChallenge(string memory name, string memory description,
uint timelimit, uint reward) public {
ChallengeCount++;
address host = msg.sender;
uint starttime = now;
uint challengercount = 0;
challenges.push(Challenge(name, host, description, starttime,
timelimit, reward, challengercount, new address[](0)));
}
function acceptChallenge(uint ChallengeCount) public {
if (now <= ((challenges[ChallengeCount].starttime) + 24)) {
challenges[ChallengeCount].challengers.push(msg.sender);
challenges[ChallengeCount].challengercount++;
uint id = challenges[ChallengeCount].challengercount;
registration[id] = msg.sender;
}
}
}
Well, in function acceptChallenge
, everything is inside an if
clause.
The simple conclusion is that the condition in the if
statement is always false
.
Looking at it, I suspect that you're expecting those 24 seconds to elapse "on their own".
This is not the case in Ganache, since there are no other participants but yourself.
So as long as you don't submit any transactions, time stands still.
Luckily for you, the Ganache EVM has a non-standard interface.
Amongst other things, this interface allows you to move forward in time.
For example, in order to jump 24 seconds forward, you can do:
web3.currentProvider.send({method: "evm_increaseTime", params: [24]});
Answered by goodvibration on November 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP