Introduce extensions for Pack contract in v5
The extensions for Pack contract have finally arrived in the SDK v5. You can now create and open packs in just a few lines of codes.
Creating a Pack
import { createNewPack } from "thirdweb/extensions/pack";
const transaction = createNewPack({
contract: packContract,
client,
recipient: "0x...",
tokenOwner: "0x...",
packMetadata: {
name: "Pack #1",
image: "image-of-pack-1",
},
openStartTimestamp: new Date(),
erc20Rewards: [
{
contractAddress: "0x...",
quantityPerReward: 1,
totalRewards: 1,
},
],
erc721Rewards: [
{
contractAddress: "0x...",
tokenId: 0n,
},
],
erc1155Rewards: [
{
contractAddress: "0x...",
tokenId: 0n,
quantityPerReward: 1,
totalRewards: 1,
},
],
});
Opening an existing Pack
import { sendTransaction } from "thirdweb";
import { openPack } from "thirdweb/extensions/pack";
const transaction = openPack({
contract,
packId: ...,
amountToOpen: ...,
});
sendTransaction({ transaction, account });