Compatible with Substrate v2.0.0

Commodities FRAME Pallet: NFTs for Substrate

This is a FRAME pallet that defines and implements an interface for managing a set of non-fungible tokens (NFTs). Assets have an owner and can be created, destroyed and transferred.

Interface

This package defines a public trait (Rust interface) for working with NFTs: the UniqueAssets trait.

UniqueAssets Trait

This trait is generic with respect to a type that is used to identify asset owners - the AccountId type. Assets with equivalent attributes (as defined by the AssetInfo type) must have equal AssetIds and assets with different AssetIds must not have equivalent attributes.

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.

Test Project

In order to help develop this pallet, it is being consumed by a test project - a work-in-progress update to the original Substratekitties tutorial.

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.