Component
Preface
It is exemplified and used with the background contracts for easier understanding.
The more general version will be component instead of background and the name of the components
component-1, component-2, component-3, etc. instead of actual names for the components.
Explanations
All Smart Contracts for Components follow the same structure. Below is exemplified with the Background Smart Contract
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 owner of lootbox, but someone else called
the name does not exist in the map for components.
doens not have the rights to call, but tried
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 to let him 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.
mint-name as it checks the type of item minted already exists in the map.Last updated
Was this helpful?