I can't figure out how to initial this data for the life of me. I have 2 structs which looks like so:

struct UserVotes {
   address userAddress;
   VoteOptionAmounts[] votes;

struct VoteInfo {
    uint256[] totalVotes;
    UserVotes[] userVotes;
    VoteChoices[] voteChoices;

I'm trying to initialize User Votes for a paticular user:

Attempt 1:

UserVotes memory newVote = UserVotes(account, new VoteOptionAmounts[](0));

Attempt 2:

VoteOptionAmounts[] storage userOptionAmounts = new VoteOptionAmounts[](0);
proposal.voteInfo.userVotes.push(UserVotes(account,  userOptionAmounts));

Attempt 3:

proposal.voteInfo.userVotes.push(UserVotes(account,  [VoteOptionAmounts(voteOptions[i].supportOption, optionWeight)]));

Nothing seems to work everything returns:

Copying of type struct VoteOptionAmounts memory[] memory to storage not yet supported.

1 Answer 1


Apparently you can just push back an empty slot first;

uint256 userVotesIndex = proposal.voteInfo.userVotes.length; 
UserVotes storage userVote = proposal.voteInfo.userVotes[userVotesIndex];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.