Skip to main content

IPack

The thirdweb Pack contract is a lootbox mechanism. An account can bundle up arbitrary ERC20, ERC721 and ERC1155 tokens into a set of packs. A pack can then be opened in return for a selection of the tokens in the pack. The selection of tokens distributed on opening a pack depends on the relative supply of all tokens in the packs.

Methods

createPack

function createPack(ITokenBundle.Token[] contents, uint256[] numOfRewardUnits, string packUri, uint128 openStartTimestamp, uint128 amountDistributedPerOpen, address recipient) external payable returns (uint256 packId, uint256 packTotalSupply)

Creates a pack with the stated contents.

Parameters

NameTypeDescription
contentsITokenBundle.Token[]The reward units to pack in the packs.
numOfRewardUnitsuint256[]The number of reward units to create, for each asset specified in contents.
packUristringThe (metadata) URI assigned to the packs created.
openStartTimestampuint128The timestamp after which packs can be opened.
amountDistributedPerOpenuint128The number of reward units distributed per open.
recipientaddressThe recipient of the packs created.

Returns

NameTypeDescription
packIduint256The unique identifer of the created set of packs.
packTotalSupplyuint256The total number of packs created.

openPack

function openPack(uint256 packId, uint256 amountToOpen) external nonpayable returns (struct ITokenBundle.Token[])

Lets a pack owner open a pack and receive the pack's reward unit.

Parameters

NameTypeDescription
packIduint256The identifier of the pack to open.
amountToOpenuint256The number of packs to open at once.

Returns

NameTypeDescription
_0ITokenBundle.Token[]undefined

Events

PackCreated

event PackCreated(uint256 indexed packId, address indexed packCreator, address recipient, uint256 totalPacksCreated)

Emitted when a set of packs is created.

Parameters

NameTypeDescription
packId indexeduint256undefined
packCreator indexedaddressundefined
recipientaddressundefined
totalPacksCreateduint256undefined

PackOpened

event PackOpened(uint256 indexed packId, address indexed opener, uint256 numOfPacksOpened, ITokenBundle.Token[] rewardUnitsDistributed)

Emitted when a pack is opened.

Parameters

NameTypeDescription
packId indexeduint256undefined
opener indexedaddressundefined
numOfPacksOpeneduint256undefined
rewardUnitsDistributedITokenBundle.Token[]undefined