Anish-Agnihotri / MultiRaffle

NFT distribution with (1) randomized, multi-winner raffles and (2) bulk on-chain metadata generation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to determine which tickets are owned by each address?

chrishol opened this issue · comments

Thanks for sharing this @Anish-Agnihotri - really great ideas and helpful examples.

My question:
The design of the claimRaffle function seems to require the caller to know where their entry lies in the raffleEntries array. Is the idea that the results could be indexed once and then provided to customers via a frontend UI?

Ideally you'd have some way of quickly finding the indices by address, but storing that might get expensive quickly.

function claimRaffle(uint256[] calldata tickets) external {

Yeah I'm looking for that to

Probably you need to find them off-chain but that may be a bit daunting. hardhat test example:

  async function getWinningIndices(address) {
    const indices = [];
    for (let i = 0; i < availableSupply; i++) {
      const entryAddress = await raffleContract.raffleEntries(i);
      if (entryAddress === address) {
        indices.push(i);
      }
    }
    return indices;
  }