Smart Contract

CoCreatable

A.7752ea736384322f.CoCreatable

Deployed

3h ago
Feb 28, 2026, 08:14:46 PM UTC

Dependents

0 imports
1// A CoCreatable contract is one where the user combines characteristics
2// to create an NFT. The contract should employ a set of dictionaries
3// at the top that provide the set from which the user can select the 
4// characteristics
5
6import MetadataViews from 0x1d7e57aa55817448
7import NonFungibleToken from 0x1d7e57aa55817448
8
9access(all) contract interface CoCreatable {
10
11    // The contract should have a dictionary of id to characteristic:
12    // eg access(contract) var garmentDatas: {UInt64: Characteristic}
13    // Dict not defined in the interface to provide flexibility to the contract
14
15    // {concat of combined characteristics: nftId}
16    // eg {materialDataId_garmentDataId_primaryColour_secondary_colour: 1}
17    access(contract) var dataAllocations: {String: UInt64}
18    // access(contract) var idsToDataAllocations: {UInt64: String}
19
20    access(all) fun getDataAllocations(): {String: UInt64}
21
22    access(all) fun getAllIdsToDataAllocations(): {UInt64: String}
23    access(all) fun getIdToDataAllocation(id: UInt64): String
24
25    
26
27    access(all) resource interface CoCreatableNFT {
28        access(all) fun getCharacteristics(): {String: {Characteristic}}?
29    }
30
31    access(all) struct interface Characteristic {
32        access(all) var id: UInt64
33
34        // Used to inform the BE in case the struct changes
35        access(all) var version: UFix64
36
37        // This is the name that will be used for the Trait, so 
38        // will be displayed on external MPs etc. Should be capitalised
39        // and spaced eg "Shoe Shape Name"
40        access(all) var traitName: String
41        // eg characteristicType = garment
42        access(all) var characteristicType: String
43        access(all) var characteristicDescription: String
44
45        // designerName, desc and address are nil if the Characteristic
46        // doesnt have one eg a primaryColor
47        access(all) var designerName: String?
48        access(all) var designerDescription: String?
49        access(all) var designerAddress: Address?
50        // Value is the name of the selected characteristic
51        // For example, for a garment, this might be "Adventurer Top" or a hex code
52        access(all) var value: AnyStruct
53        access(all) var rarity: MetadataViews.Rarity?
54
55        // The media files associated with the Characteristic, not all will have this property. These will very rarely be included as part of a trait. 
56        // access(all) var media: MetadataViews.Medias?
57
58        access(contract) fun updateCharacteristic(key: String, value: AnyStruct)
59
60        //Helper function that converts the characteristics to traits
61        access(all) fun convertToTraits(): [MetadataViews.Trait]
62    }
63
64}
65