0

My smart contract has a dynamic array inside a struct, however, while there are no errors, it is not running properly. Can you have a dynamic array in a struct in solidity? If not, should I use a mapping?

0

The fact that you are using input parameter uint challengeid in all functions except for the one which inserts a new item into your data structure (function createChallenge), implies that you should:

  1. Change Challenge[] public challenges to mapping (uint => Challenge) public challenges
  2. Add input parameter uint challengeid in function createChallenge
  3. Change challenges.push(Challenge(...)) to challenges[challengeid] = Challenge(...)
| improve this answer | |

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.