Lootbox

Explanations

Traits used

This trait enforces that the standard for NFTs is implemented in this smart contract through SIP009.

(use-trait nft-trait .nft-trait.nft-trait)

Errors and Constants

Errors for different cases such as:

  • should be called by admin, but someone else called

  • should be called by owner of lootbox, but someone else called

  • collection has reached the mint limit but a new mint was called

  • the block height was not registered

  • the lootbox block height is bigger than current confirmed block height

  • can't convert byte to uint

Limit of lootboxes per collection

(define-constant err-admin-only (err u100))
(define-constant err-owner-only (err u101))
(define-constant err-mint-limit-exceeded (err u102))
(define-constant err-missing-block-height (err u402))
(define-constant err-lootbox-locked (err u403))
(define-constant err-invalid-random (err u404))

(define-constant limit-mint u255)

Variable Data Stored - Maps and Vars

SIP009: Standard Implementations for NFTs

Open Functions and Info

Because the data is kept in the Smart Contract it should be public to all the users, not only the owner of a specific NFT.

It would make no sense if, after the specified block-height, only the owner of the lootbox will know what he can redeem from the lootbox and put it up for sale instead. The buyer would be unaware of the value till he purchased it. Then, the cycle would repeat because the item is not as expected.

That's why everybody should know the lootbox value at the same time. We opted for a faster unboxing experience, letting the user claim his item directly in the next block. If a market for lootboxes is the target, the block-height of the lootbox should be increased from the next block to at least a few hundred blocks.

Get-random - the random value for a given lootbox. Pick the first byte and convert it to uint.

Component-for-value - with the converted value from get-random call this function and get the component the lootbox will mint.

Is-openable - check if the current minted block height is higher than the lootbox block height and ,if so, return true .

Item-for-lootbox - directly tell what item will be redeemed from an unlocked lootbox.

Conversion Functions

Convert from 1 byte to uint

  • input: between 0x00 and 0xff

  • output: between 0 and 255

Convert from uint to byte

  • input: between 0 and 255

  • output: between 0x00 and 0xff

Lootbox Admin

Mint - private function to mint the lootbox nft. Sets the block-height for the minted nft.

Create-lootbox - public function callable only by admin till the mint limit is reach.

After the lootbox is minted to the user's address, the admin does not have any control to it.

Set-admin - change the admin of the smart contract. The old address will not be able to call the admin functions after the call is confirmed, while the new address will be able afterwards.

Lootbox Owner

The lootbox owner can open it and get the item from the item's NFT collection. He gets it in the same call because this function acts like an admin to the other smart-contract and in this way it stops the abuse for mint-names, thereby burning the prior lootbox. Also the id is directly related to the lootbox so users inserting any value as parameter would not interfere with the pick of the item that is supposed to be minted.

Last updated

Was this helpful?