git.delta.rocks / unique-network / refs/commits / 10c381b42680

difftreelog

source

doc/application_development.md6.7 KiBsourcehistory
1# Building an NFT Application23## Architecture45Both centralized and serverless architectures are supported and application creator can decide which one to use depending on how much logic and data they intend to manage off-chain and off-line.67### Server-based architecture89In server-based architecture the application creator manually creates NFT collections and authorizes server to perform operations on each collection. See NFT palette methods that have admin permission level to understand better what server (or administrators) can do.1011![](server_architecture.png)1213### Serverless architecture1415In serverless architecture the application creator does all initialization and token distribution manually. Alternatively, smart contracts may be used in order to implement some distribution mechanics such as token sales or claiming. The dApp has access to all properties of an NFT token, but it does not have any elevated permissions, since it resides on user site. All operations happen on user's behalf signed by user's private key.1617![](serverless_architecture.png)1819## Custom Types for JS API2021```22{23  "Schedule": {24    "version": "u32",25    "put_code_per_byte_cost": "Gas",26    "grow_mem_cost": "Gas",27    "regular_op_cost": "Gas",28    "return_data_per_byte_cost": "Gas",29    "event_data_per_byte_cost": "Gas",30    "event_per_topic_cost": "Gas",31    "event_base_cost": "Gas",32    "call_base_cost": "Gas",33    "instantiate_base_cost": "Gas",34    "dispatch_base_cost": "Gas",35    "sandbox_data_read_cost": "Gas",36    "sandbox_data_write_cost": "Gas",37    "transfer_cost": "Gas",38    "instantiate_cost": "Gas",39    "max_event_topics": "u32",40    "max_stack_height": "u32",41    "max_memory_pages": "u32",42    "max_table_size": "u32",43    "enable_println": "bool",44    "max_subject_len": "u32"45  },46  "NftItemType": {47    "Collection": "u64",48    "Owner": "AccountId",49    "Data": "Vec<u8>"50  },51  "CollectionType": {52    "Owner": "AccountId",53    "NextItemId": "u64",54    "Name": "Vec<u16>",55    "Description": "Vec<u16>",56    "TokenPrefix": "Vec<u8>",57    "CustomDataSize": "u32",58    "Sponsor": "AccountId",59    "UnconfirmedSponsor": "AccountId"60  },61  "Address": "AccountId",62  "LookupSource": "AccountId",63  "Weight": "u64"64}65```6667## NFT Palette Methods6869### Collection Management7071#### CreateCollection7273##### Description74This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner and admin of the collection are set to the address that signed the transaction. Both addresses can be changed later.7576##### Permissions77Anyone7879##### Parameters80customDataSz: Size of NFT properties data.8182##### Events83CollectionCreated84CollectionID: Globally unique identifier of newly created collection.85Owner: Collection owner8687#### ChangeCollectionOwner8889##### Description90Change the owner of the collection9192##### Permissions93Collection Owner9495##### Parameters96CollectionId9798#### DestroyCollection99100##### Description101DANGEROUS: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.102103##### Permissions104Collection Owner105106##### Parameters107CollectionId108109#### CreateItem110111##### Description112This method creates a concrete instance of NFT Collection created with CreateCollection method.113114##### Permissions115Collection Owner116Collection Admin117118##### Parameters119CollectionID: ID of the collection120Properties: Array of bytes that contains NFT properties. Since NFT Module is agnostic of properties’ meaning, it is treated purely as an array of bytes121Owner: Address, initial owner of the NFT122123##### Events124ItemCreated125ItemId: Identifier of newly created NFT, which is unique within the Collection, so the NFT is uniquely identified with a pair of values: CollectionId and ItemId.126127#### BurnItem128129##### Description130This method destroys a concrete instance of NFT.131132##### Permissions133Collection Owner134Collection Admin135Current NFT Owner136137##### Parameters138CollectionID: ID of the collection139ItemID: ID of NFT to burn140141##### Events142ItemDestroyed143CollectionID144ItemId: Identifier of burned NFT145146147#### AddCollectionAdmin148149##### Description150NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.151152This method adds an admin of the Collection.153154##### Permissions155Collection Owner156Collection Admin157158##### Parameters159CollectionID: ID of the Collection to add admin for160Admin: Address of new admin to add161162#### RemoveCollectionAdmin163164##### Description165Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.166167##### Permissions168Collection Owner169Collection Admin170171##### Parameters172CollectionID: ID of the Collection to remove admin for173Admin: Address of admin to remove174175### Item Ownership and Transfers176This group of methods allows managing NFT ownership.177178#### GetOwner179180##### Description181Return the address of the NFT owner. 182183##### Permissions184Anyone185186##### Parameters187CollectionId188ItemId: ID of the NFT189190##### Returns191Owner address192193#### BalanceOf194195##### Description196This method is included for compatibility with ERC-721. Return the total count of NFTs of a given Collection that belong to a given address. 197198##### Permissions199Anyone200201##### Parameters202CollectionId203Address to count NFTs for204205##### Returns206Total count of NFTs for Address207208209#### Transfer210211##### Description212Change ownership of the NFT.213214##### Permissions215Collection Owner216Collection Admin217Current NFT owner218219##### Parameters220Recipient: Address of token recipient221ClassId: ID of item class222ItemId: ID of the item223224#### TransferFrom225226##### Description227Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.228229##### Permissions230Collection Owner231Collection Admin232Current NFT owner233Address approved by current NFT owner234235##### Parameters236Recipient: Address of token recipient237ClassId: ID of item class238ItemId: ID of the item239240241#### Approve242243##### Description244Set, change, or remove approved address to transfer the ownership of the NFT.245246##### Permissions247Collection Owner248Collection Admin249Current NFT owner250251##### Parameters252Approved: Address that is approved to transfer this NFT or zero (if needed to remove approval)253ClassId: ID of item class254ItemId: ID of the item255256#### GetApproved257258##### Description259Get the approved address for a single NFT.260261##### Permissions262Anyone263264##### Parameters265ClassId: ID of item class266ItemId: ID of the item267268##### Returns269Approved address