Hey @Anish-Agnihotri, thanks for providing this sample contract. Both this and the article are really good resources!
I'm looking at the refund mechanism and wondering if it wouldn't be easier to just compare the number of winningTickets
with the entriesPerAddress(address) and just send the MINT_COST * (entriesPerAddress - winningTickets) as a refund ?
The advantage here is that we don't need to keep track of the losing tickets as well (which would have swapped indices because of the shuffling.
// Refund losing tickets
uint256 entriesPerAddress = entriesPerAddress[msg.sender];
if (winningTickets != entriesPerAddress) {
// Payout value equal to number of bought tickets - paid for winning tickets
(bool sent, ) = payable(msg.sender).call{
value: (entriesPerAddress - winningTickets) * MINT_COST
}("");
require(sent, "Unsuccessful in refund");
}
// Emit claim event
emit RaffleClaimed(msg.sender, winningTickets, entriesPerAddress - winningTickets);
Hey @Anish-Agnihotri, thanks for providing this sample contract. Both this and the article are really good resources!
I'm looking at the refund mechanism and wondering if it wouldn't be easier to just compare the number of
winningTickets
with theentriesPerAddress(address)
and just send theMINT_COST * (entriesPerAddress - winningTickets)
as a refund ?The advantage here is that we don't need to keep track of the losing tickets as well (which would have swapped indices because of the shuffling.