Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Thirdweb Loot Pack
copy icon
thirdweb
• version 1.0.0
NFT
Token
ERC20
ERC721
ERC1155
Utility
Wrapper
Audited

Thirdweb Loot Pack

Audited

The pack contract lets you bundle ERC20, ERC721 and, ERC1155 tokens together into ERC1155 NFTs that act as randomized loot boxes. The packs are ERC1155 NFTs themselves, which can have the metadata you'd expect of an NFT, such as a name, image, description, etc. When a pack is opened, a pre-defined quantity of tokens are randomly selected from the ones that were used to create the packs (that haven't already been selected), and awarded to the opener. The pack NFT is burned as it's opened. You can configure how many tokens get selected for the pack: How many tokens are in each "unit" (for ERC20 & ERC1155 tokens -one unit could be multiple tokens). How many units are in each pack.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

thirdweb

Recent Use

🍞 0x77eA downloaded

Last Publish

10/23/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
initialize(address,string,string,string,address,uint256) :
This function is the initializer for the ERC-1155 contract. It sets up the contract with the given parameters, including the default admin, name, symbol, contract URI, trusted forwarders, royalty recipient, and royalty BPS. It also sets up the roles for the default admin, transfer, minter, and asset. Finally, it sets up the default royalty info. (autogenerated documentation)
contractType() :
This function returns a bytes32 value that represents the type of contract. It does this by simply returning the value of the MODULE_TYPE constant, which is set when the contract is deployed. (autogenerated documentation)
contractVersion() :
This function is a getter function that returns the version of the contract. It is a pure function, meaning that it does not modify the state of the contract and does not interact with the blockchain. It simply returns the value of the constant variable VERSION, which is a uint8 (unsigned 8-bit integer) that stores the version of the contract. (autogenerated documentation)
uri(uint256) :
This function returns the Uniform Resource Identifier (URI) of a given token ID. It works by calling the getUriOfBundle() function, which takes the token ID as an argument and returns the corresponding URI. (autogenerated documentation)
supportsInterface(bytes4) :
This function is used to check if a contract supports a given interface. It does this by comparing the given interfaceId to the interfaceIds of the contracts that the contract supports (ERC1155Receiver, ERC1155Upgradeable, IERC165, IERC2981Upgradeable, IERC721Receiver, and IERC1155Receiver). If the given interfaceId matches any of the supported interfaceIds, the function returns true, otherwise it returns false. (autogenerated documentation)
createPack(uint256[],string,uint128,uint128,address) :
This function creates a pack of tokens, which is a collection of different tokens that can be opened and distributed to users. It takes in an array of tokens, an array of the number of reward units for each token, a pack URI, an open start timestamp, an amount distributed per open, and a recipient address. It then assigns the pack an ID, and stores the open start timestamp and amount distributed per open in the packInfo mapping. It then mints the pack to the recipient address, and emits an event to signal that the pack has been created. (autogenerated documentation)
addPackContents(uint256,uint256[],address) :
This function adds contents to a pack with a given ID. It requires that the caller has the minterRole, that the contents and number of reward units are valid, and that the recipient has a balance of the pack. It then checks that the assetRole is valid for each content, and escrows the contents with the given number of reward units, pack ID, and amount per open. Finally, it mints the new supply to the recipient and emits a PackUpdated event. (autogenerated documentation)
openPack(uint256,uint256) :
This function allows a user to open a pack with a given ID and amount. It first checks that the sender is a trusted forwarder or the origin of the transaction. It then checks that the user has enough balance to open the pack. It then checks that the pack can be opened at the current timestamp. It then calculates the reward units for the user based on the amount to open and the amount distributed per open. It then burns the amount of tokens from the user's balance, transfers the reward units to the user, and emits an event to log the pack opening. (autogenerated documentation)
escrowPackContents(uint256[],string,uint256,uint256,bool) :
This function is used to store the contents of an escrow pack. It takes in an array of tokens, an array of the number of reward units associated with each token, a pack URI, a pack ID, an amount per open, and a boolean value to indicate whether the pack is being updated or not. The function first checks that the total amount of each token is not 0, that the total amount is divisible by the number of reward units, and that the token type is not ERC721 or the total amount is 1. It then calculates the sum of the reward units and checks that it is divisible by the amount per open. It then calculates the supply to mint. If the (autogenerated documentation)
getRewardUnits(uint256,uint256,uint256) :
This function is used to generate a reward for a given pack. It takes in the pack ID, the number of packs to open, the reward units per open, and the pack info as parameters. It then calculates the total number of reward units to distribute, and creates an array of tokens to store the reward units. It then uses a random value to generate a target, and iterates through the pack contents to find the token that matches the target. It then updates the token in the bundle and adds it to the reward units array. Finally, it returns the reward units array. (autogenerated documentation)
s function getPackContents(uint256) :
This function retrieves the contents of a pack, given its ID. It first retrieves the PackInfo associated with the given ID from the packInfo mapping. It then calculates the total number of tokens in the bundle and creates two arrays of the same size, one for the tokens and one for the per unit amounts. It then iterates through the bundle and adds each token to the contents array. Finally, it sets the perUnitAmounts array to the perUnitAmounts from the PackInfo. (autogenerated documentation)
s function _canSetOwner() :
This function checks if the message sender has the default admin role. It does this by calling the hasRole() function, which takes in the default admin role and the message sender as parameters. If the message sender has the default admin role, the function returns true, otherwise it returns false. (autogenerated documentation)
_canSetRoyaltyInfo() :
This function checks if the message sender has the default admin role and returns a boolean value indicating whether they do or not. This is used to determine if the sender has permission to set royalty information. (autogenerated documentation)
_canSetContractURI() :
This function checks if the message sender has the default admin role and returns a boolean value indicating whether they do or not. It is used to determine if the message sender has permission to set the contract URI. (autogenerated documentation)
generateRandomValue() :
This function generates a random number using a combination of the msg.sender, the blockhash of the previous block, and the difficulty of the current block. It does this by taking the keccak256 hash of the combination of these three values, and then converting the resulting hash into a uint256 value. This value is then returned as the random number. (autogenerated documentation)
_beforeTokenTransfer(address,address,address,uint256[],uint256[]) :
This function is an override of the _beforeTokenTransfer function in the ERC1155 contract. It is used to check that the transfer of tokens is allowed and to update the total supply of tokens. It checks that the sender and receiver of the tokens have the transfer role, and if the sender is address(0) (the contract itself) it adds the amount of tokens to the total supply. If the receiver is address(0) it subtracts the amount of tokens from the total supply. It also checks if the token is a pack token and if so, sets the canUpdatePack flag to false. (autogenerated documentation)
_msgSender() :
This function is used to retrieve the address of the sender of the current message. It works by calling the _msgSender() function from the ERC2771ContextUpgradeable contract, which returns the address of the sender. (autogenerated documentation)
_msgData() :
This function is used to retrieve the data associated with a given message call. It works by calling the _msgData() function from the ERC2771ContextUpgradeable contract, which returns the data associated with the message call as a byte array. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i thirdweb-pack
copy icon

Recent Use

🍞 0x77eA downloaded

Last Publish

10/23/2022

Version

1.0.0

Creator

thirdweb

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.