How to shuffle items when lazy minting

In this guide, we'll learn how to shuffle items during lazy minting using the thirdweb SDK.

 

The shuffling feature is not a part of the SDK. What you need to do is shuffle the array of items (NFTInput[]) yourself, then pass the randomized result to the lazyMint method.

const shuffleData = (array: NFTInput[]) =>
  array
    .map((value) => ({ value, sort: Math.random() }))
    .sort((a, b) => a.sort - b.sort)
    .map(({ value }) => value);

const nftsToLazyMint: NFTInput[] = [
  { name: "token 1" },
  { name: "token 2" },
  { name: "token 3" },
];

const shuffled: NFTInput[] = shuffleData(nftsToLazyMint);

const mint = await lazyMint({
  contract: yourNftContract,
  nfts: shuffled,
});
 

That’s it, your issue is resolved now!


Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.

 
Did this answer your question?
😞
😐
🤩