07 / 15Module 2: Model NFTs in RellAdvanced
Define the NFT model
In this project, you define a complete NFT model on-chain and implement it in Rell.
Begin with a base entity called nft. It represents an NFT through a unique ID and a mutable attribute that holds the NFT's owner. Create the file src/rell_marketplace/nft.rell and add this code:
entity nft { key id: byte_array = op_context.transaction.tx_rid; mutable owner: account; index owner;}The id property holds the Transaction RID of the minted NFT. The owner property is mutable and has the type account. Because you can update the owning account, you can transfer the NFT to another account.
The account entity comes from the FT4 library and represents an account registered in FT4. For details, see the FT4 accounts documentation.
An index on owner speeds up queries that look up who owns an NFT. The trade-off is that changing the owner becomes a more expensive operation. With the base entity defined, you can now build the Gaming Trade Card NFT and give it its own attributes.
entity nft_card { key nft; strength: integer; health: integer;}Here is what each part does:
-
key nftlinks the card to the NFT entity and enforces uniqueness on that link. -
strengthandhealthare the attributes that make each card distinct.
With these few steps, you have a simple NFT model in place.