This is a Tetcore module 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.
This package defines a public module for working with NFTs, providing functionality for:
- Collections: Create and manage NFT collections with optional max supply
- Minting: Create new NFTs within collections
- Burning: Destroy NFTs
- Transferring: Transfer ownership between accounts
- Approvals: Approve operators to transfer on behalf of owners
- Marketplace: List NFTs for sale, buy listings
- CollectionId: Unique identifier for an NFT collection
- NftId: Unique identifier for an individual NFT within a collection
- AssetId: Composite identifier combining collection and NFT IDs
- AssetInfo: Metadata including name, description, image URI, attributes
- Collection: Collection configuration including owner, max supply, royalty
The module maintains:
collections: Map of all collectionsnfts: Map of all NFT dataownership: Map of asset ownershiplistings: Active marketplace listings
let mut nft_module = NftModule::new();
let collection_id = nft_module.create_collection(
"My Collection".to_string(),
"Description of my collection".to_string(),
owner_address,
Some(10000), // max supply
)?;let asset_id = nft_module.mint(
collection_id,
recipient_address,
AssetInfo::new("NFT Name".to_string(), "Description".to_string())
.with_image("ipfs://...".to_string())
.add_attribute("rarity".to_string(), "legendary".to_string()),
)?;nft_module.transfer(&asset_id, from_address, to_address)?;nft_module.list(
asset_id,
seller_address,
1000, // price
currency_address,
expires_at_block,
)?;This module implements a variation of the UniqueAssets trait:
total() -> u64: Total number of NFTsowner_of(AssetId) -> Address: Get owner of an NFTmint() -> Result<AssetId>: Create new NFTburn(AssetId): Destroy NFTtransfer(AssetId, Address, Address): Transfer ownership
This implementation uses sorted lists of assets per owner for efficient trading. Assets are sorted by ID to enable:
- Fast lookups during transfer
- Efficient burning operations
- Ordered enumeration
Built-in marketplace functionality supports:
- Fixed-price listings
- Expiration times
- Royalty support for collections
The module includes comprehensive tests:
cargo testRun specific test modules:
cargo test --lib nftTo integrate this module into your Tetcore runtime:
- Add to your Cargo.toml:
tetcore-mod-nft = { path = "../tetcore-mod-nft" }- Configure in your runtime:
impl tetcore_mod_nft::Config for Runtime { ... }- Add to runtime composition
This project was inspired by works such as:
- The ERC-721 specification
- OpenZeppelin's ERC-721 implementation
- Substrate's NFT pallet
- The original Substratekitties project
- danforbes' pallet-nft
See LICENSE file.