Commodities FRAME Pallet: NFTs for Substrate

This is a FRAME pallet that defines and implements a non-fungible token (NFT) interface as well as an interface for managing a set of such assets, including asset ownership, creation, destruction and transfer.

Interface

This package defines two public traits (Rust interfaces) for working with NFTs: the NFT trait and the UniqueAssets trait.

NFT Trait

The NFT trait uses two types to define a unique asset:

Assets with equivalent attributes (as defined by the Info type) must have an equal ID and assets with different IDs must not have equivalent attributes.

UniqueAssets Trait

This trait is generic with respect to a type that implements the NFT trait; it defines the type abstractions and public functions needed to manage a set of unique assets.

Types

Functions

Reference Implementation

The reference implementation defined in this project is referred to as a "commodity" - a unique asset that is designed for frequent trading. In order to optimize for this use-case, sorted lists of assets are stored per owner. Although maintaining a sorted list is trivial with Rust vectors, which implement a binary search API that can be used for sorted insertion, it introduces significant overhead when an asset is created because the entire list must be decoded from the backing trie in order to insert the new asset in the correct spot. Maintaining a sorted asset list is desireable for the commodity use case, however, because it allows assets to be efficiently located when destroying or transferring them. An alternative implementation, the Keepsake pallet, is in the works :rocket:

Tests

Refer to the mock runtime and provided tests to see the NFT implementation in action.

Acknowledgements

This project was inspired by works such as the following:

Thanks to the following people who helped me overcome my relatively limited understanding of Rust.

Upstream

This project was forked from the Substrate DevHub Pallet Template.