Giter VIP home page Giter VIP logo

pallet-nft's Introduction

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

  • AssetId: a URI for an asset
  • AssetInfo: a set of attributes that uniquely describes an asset
  • AssetLimit: the maximum number of assets, expressed as an unsigned 128-bit integer, that may exist in this set at once
  • UserAssetLimit: the maximum number of assets, expressed as an unsigned 64-bit integer, that any single account may own from this set at once

Functions

  • total() -> u128: returns the total number of assets in this set of assets
  • burned() -> u128: returns the total number of assets from this set that have been burned
  • total_for_account(AccountId) -> u64: returns the total number of asset from this set that are owned by a given account
  • assets_for_account(AccountId) -> Vec<(AssetId, AssetInfo)>: returns the list of assets from this set that are owned by a given account
  • owner_of(AssetId) -> AccountId: returns the ID of the account that owns the given asset from this set
  • mint(AccountId, AssetInfo) -> Result<AssetID, DispatchError>: use the given attributes to create a new unique asset that belongs to this set and assign ownership of it to the given account
    • Failure cases: asset duplication, asset limit reached for set, asset limit for this set reached for account
  • burn(AssetId) -> DispatchResult: destroy the given asset
    • Failure cases: asset doesn't exist
  • transfer(AccountId, AssetId) -> DispatchResult: transfer ownership of the given asset from this set from its current owner to a given target account
    • Failure cases: asset doesn't exist, asset limit for this set reached for target account

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 ๐Ÿš€

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.

pallet-nft's People

Contributors

danforbes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.