Item

Preface

It is exemplified and used with the background contracts for easier understanding.

The more general version will be item instead of background and the name of the items

item-common-1, item-common-2, item-rare-1, etc. instead of actual names for the items.

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

Errors for different cases such as:

  • should be called by admin, but someone else called

  • should be called by owner, but someone else called

  • the name is not part of the existent in map for items

(define-constant err-admin-only (err u100))
(define-constant err-owner-only (err u101))
(define-constant err-invalid-name (err u301))

Variable Data Stored - Maps and Vars

Every NFT has a token-url value attributed. This helps in calling the get-token-uri function.

Map name-url - keeps all types of items the collection has. On deployment it will have DarkPurple, Emerald, Goldie, Orange, Purple, Sunset with their token-URI.

Also keep contract-owner and contract-lootbox to let them perform mints, add and update new item-names to the collection and remove old ones.

SIP009: Standard Implementations for NFTs

Item Name-URI

Get-name-url - anyone can get the saved URI for the specified URI

Set-name-url - only admins can store the URI to the name

Remove-name-url - only admins can remove the key name from the map

Item Mint

There are two ways to mint a new item, by using directly the URI of the NFT, or by minting with the name and getting the URI from the values stored on-chain in the map. Safer and easier to use mint-name as it checks the type of item minted already exists in the map.

Last updated

Was this helpful?