Smart Contract

MatrixWorldAssetsNFT

A.f20df769e658c257.MatrixWorldAssetsNFT

Deployed

6d ago
Feb 21, 2026, 06:53:14 PM UTC

Dependents

5 imports
1import NonFungibleToken from 0x1d7e57aa55817448
2import ViewResolver from 0x1d7e57aa55817448
3import MetadataViews from 0x1d7e57aa55817448
4import FungibleToken from 0xf233dcee88fe0abe
5import LicensedNFT from 0xf20df769e658c257
6
7// MatrixWorldAssetsNFT token contract
8//
9access(all) contract MatrixWorldAssetsNFT : NonFungibleToken, LicensedNFT {
10
11    access(all) var totalSupply: UInt64
12
13    access(all) let collectionPublicPath: PublicPath
14    access(all) let collectionStoragePath: StoragePath
15    access(all) let minterStoragePath: StoragePath
16
17    access(all) event ContractInitialized()
18    access(all) event Withdraw(id: UInt64, from: Address?)
19    access(all) event Deposit(id: UInt64, to: Address?)
20
21    access(all) event Mint(id: UInt64, creator: Address, metadata: {String:String}, royalties: [Royalty])
22
23    access(all) event Destroy(id: UInt64)
24
25    access(all) resource interface Metadata {
26        access(all) fun getMetadata(id: UInt64): {String:String}
27    }
28
29    access(all) struct Royalty: LicensedNFT.Royalty {
30        access(all) let address: Address
31        access(all) let fee: UFix64
32
33        init(address: Address, fee: UFix64) {
34            self.address = address
35            self.fee = fee
36        }
37    }
38
39    access(all) resource NFT: NonFungibleToken.NFT {
40        access(all) let id: UInt64
41        access(all) let creator: Address
42        access(self) let metadata: {String:String}
43
44        init(id: UInt64, creator: Address, metadata: {String:String}, royalties: [{LicensedNFT.Royalty}]) {
45            self.id = id
46            self.creator = creator
47            self.metadata = metadata
48        }
49
50        access(all) view fun getMetadata(): {String:String} {
51            return self.metadata
52        }
53
54       access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
55        return <- create Collection()
56       }
57
58       access(all) view fun getViews(): [Type] {
59        return [
60            Type<MetadataViews.Display>(),
61                Type<MetadataViews.ExternalURL>(),
62                Type<MetadataViews.Serial>(),
63                Type<MetadataViews.NFTCollectionData>(),
64                Type<MetadataViews.NFTCollectionDisplay>(),
65                Type<MetadataViews.EVMBridgedMetadata>(),
66                Type<MetadataViews.Royalties>()
67        ]
68       }
69
70       access(all) fun getRoyalties(): [{LicensedNFT.Royalty}] {
71           panic("Deprecated");
72        }
73
74       access(all) fun resolveView(_ view: Type): AnyStruct? {
75        switch view {
76            case Type<MetadataViews.Display>():
77                return MetadataViews.Display(
78                    name: self.metadata["collection"]!,
79                    description: self.metadata["description"]!,
80                    thumbnail: MetadataViews.HTTPFile(
81                        url: self.metadata["image"]!
82                    )
83                )
84            case Type<MetadataViews.Royalties>():
85                return MetadataViews.Royalties([])
86            case Type<MetadataViews.Serial>():
87                return MetadataViews.Serial(self.id)
88            case Type<MetadataViews.ExternalURL>():
89                return MetadataViews.ExternalURL("https://www.world3.ai")
90            case Type<MetadataViews.NFTCollectionData>():
91                return MatrixWorldAssetsNFT.resolveContractView(resourceType: Type<@MatrixWorldAssetsNFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionData>())
92            case Type<MetadataViews.NFTCollectionDisplay>():
93                return MatrixWorldAssetsNFT.resolveContractView(resourceType: Type<@MatrixWorldAssetsNFT.NFT>(), viewType: Type<MetadataViews.NFTCollectionDisplay>())
94            case Type<MetadataViews.EVMBridgedMetadata>():
95                return MetadataViews.EVMBridgedMetadata(
96                    name: "MatrixWorldAssets",
97                    symbol: "MWA",
98                    uri: MetadataViews.URI(
99                        baseURI: self.metadata["image"]!, // defining baseURI results in a concatenation of baseURI and value
100                        value: "" 
101                    )
102                )
103
104        }
105        return nil
106       }
107    }
108
109    access(all) resource Collection: NonFungibleToken.Collection, LicensedNFT.CollectionPublic, Metadata {
110        access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
111
112        init() {
113            self.ownedNFTs <- {}
114        }
115
116        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
117            let supportedTypes: {Type: Bool} = {}
118            supportedTypes[Type<@MatrixWorldAssetsNFT.NFT>()] = true
119            return supportedTypes
120        }
121
122        /// Returns whether or not the given type is accepted by the collection
123        /// A collection that can accept any type should just return true by default
124        access(all) view fun isSupportedNFTType(type: Type): Bool {
125            return type == Type<@MatrixWorldAssetsNFT.NFT>()
126        }
127
128        access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
129            let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("Missing NFT")
130            emit Withdraw(id: token.id, from: self.owner?.address)
131            return <- token
132        }
133
134        access(all) fun deposit(token: @{NonFungibleToken.NFT}) {
135            let token <- token as! @MatrixWorldAssetsNFT.NFT
136            let id: UInt64 = token.id
137            let dummy <- self.ownedNFTs[id] <- token
138            destroy dummy
139            emit Deposit(id: id, to: self.owner?.address)
140        }
141
142        access(all) view fun getIDs(): [UInt64] {
143            return self.ownedNFTs.keys
144        }
145
146        /// Gets the amount of NFTs stored in the collection
147        access(all) view fun getLength(): Int {
148            return self.ownedNFTs.length
149        }
150
151        access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
152            return &self.ownedNFTs[id]
153        }
154
155        /// Borrow the view resolver for the specified NFT ID
156        access(all) view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}? {
157            if let nft = &self.ownedNFTs[id] as &{NonFungibleToken.NFT}? {
158                return nft as &{ViewResolver.Resolver}
159            }
160            return nil
161        }
162    
163        access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
164            return <- create Collection()
165        }
166
167        access(all) view fun getMetadata(id: UInt64): {String:String} {
168            panic("Deprecated");
169        }
170
171        access(all) view fun getRoyalties(id: UInt64): [{LicensedNFT.Royalty}] {
172            panic("Deprecated");
173        }
174    }
175
176    access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
177        return <- create Collection()
178    }
179
180    access(all) view fun getContractViews(resourceType: Type?): [Type] {
181        return [
182            Type<MetadataViews.NFTCollectionData>(),
183            Type<MetadataViews.NFTCollectionDisplay>(),
184            Type<MetadataViews.EVMBridgedMetadata>()
185        ]
186    }
187
188    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
189        switch viewType {
190            case Type<MetadataViews.NFTCollectionData>():
191                let collectionsData = MetadataViews.NFTCollectionData(
192                    storagePath: self.collectionStoragePath,
193                    publicPath: self.collectionPublicPath,
194                    publicCollection: Type<&MatrixWorldAssetsNFT.Collection>(),
195                    publicLinkedType: Type<&MatrixWorldAssetsNFT.Collection>(),
196                    createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
197                        return <-MatrixWorldAssetsNFT.createEmptyCollection(nftType: Type<@MatrixWorldAssetsNFT.NFT>())
198                    })
199                )
200                return collectionsData
201            case Type<MetadataViews.NFTCollectionDisplay>():
202                let squareMedia= MetadataViews.Media(
203                    file: MetadataViews.HTTPFile(
204                        url: "https://world3.ai/assets/WORLD3Logo_black.png"
205                    ),
206                    mediaType: "image/png"
207                )
208                let bannerMedia= MetadataViews.Media(
209                    file: MetadataViews.HTTPFile(
210                        url: "https://world3.ai/assets/Matrixworld_poster.png"
211                    ),
212                    mediaType: "image/png"
213                )
214                return MetadataViews.NFTCollectionDisplay(
215                    name: "WORLD3 WORLD Assets",
216                    description: "WORLD3 is an AI-Powered Autonomous World that acts as a social space and entertainment hub where users can PLAY, CREATE, and CONNECT.",
217                    externalURL: MetadataViews.ExternalURL("https://world3.ai/"),
218                    squareImage: squareMedia,
219                    bannerImage: bannerMedia,
220                    socials: {
221                        "twitter": MetadataViews.ExternalURL("https://x.com/WORLD3_AI")
222                    }
223                )
224            case Type<MetadataViews.EVMBridgedMetadata>():
225                return MetadataViews.EVMBridgedMetadata(
226                    name: "MatrixWorldAssets",
227                    symbol: "MWA",
228                    uri: MetadataViews.URI(
229                        baseURI: "https://world3.ai",
230                        value: "" 
231                    )
232                )
233            default:
234                return nil
235        }
236    }
237
238    access(all) resource Minter {
239        access(all) fun mintTo(creatorAddress: Address, creator: &{NonFungibleToken.CollectionPublic}, metadata: {String:String}) {
240            let token <- create NFT(
241                id: MatrixWorldAssetsNFT.totalSupply,
242                creator: creatorAddress,
243                metadata: metadata,
244                royalties: [] 
245            )
246            MatrixWorldAssetsNFT.totalSupply = MatrixWorldAssetsNFT.totalSupply + 1
247            let tokenRef = &token as &{NonFungibleToken.NFT}
248            emit Mint(id: token.id, creator: creatorAddress, metadata: metadata, royalties: [])
249            creator.deposit(token: <- token)
250        }
251    }
252
253    access(all) fun minter(): &Minter {
254        return self.account.storage.borrow<&Minter>(from: self.minterStoragePath) ?? panic("Could not borrow minter reference")
255    }
256
257    init() {
258        self.totalSupply = 0
259        self.collectionPublicPath = /public/MatrixWorldAssetNFTCollection
260        self.collectionStoragePath = /storage/MatrixWorldAssetNFTCollection
261        self.minterStoragePath = /storage/AssetNFTMinter
262
263        let minter <- create Minter()
264        self.account.storage.save(<- minter, to: self.minterStoragePath)
265
266        let collection <- self.createEmptyCollection(nftType: Type<@MatrixWorldAssetsNFT.NFT>())
267        self.account.storage.save(<- collection, to: self.collectionStoragePath)
268
269        emit ContractInitialized()
270    }
271}
272