1

For example, if I have:

mapping(address => Tickets[]) ticketEntries;

Can there me multiple tickets belonging to the same address in the ticketEntries mapping? ie:

ticketEntries[0] = (0x100..., ticket1);
ticketEntries[1] = (0x100..., ticket2);
etc...
1

Since you have each address mapped to an array of tickets, you should be able to do what you're trying to, but you're going about it in the wrong way.

ticketEntries[0x100...].push(ticket1);
ticketEntries[0x100...].push(ticket2);

This achieves what you want (I think) but it's not using duplicate entries in the mapping, it's simply adding multiple elements to an array. Since you are mapping addresses to arrays, you can refer to the array of Tickets associated with the address 0x100... using:

ticketEntries[0x100...]

To refer to different elements in that array you can just use:

ticketEntries[0x100...][0]
ticketEntries[0x100...][0]
1

No.

There's also an error in your example. ticketEntries[0] would be in error since 0 is not an address. So it would be ticketEntries[0x100...] = ticket.

So that said, mappings use unique keys to refer to the value. So no, there can not be duplicate values and your second assignment of ticket2 will overwrite the first.

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.