1- pub contract EmojiNFT {
2- pub event NFTMinted (id : UInt64 , owner : Address , emojiCollage : String )
3- pub event NFTTransferred (id : UInt64 , from : Address , to : Address )
4- pub event CollectionCreated (owner : Address )
5-
6- pub struct Metadata {
7- pub let name : String
8- pub let description : String
9- pub let image : String
10- pub let attributes : {String : String }
11- pub let createdAt : UFix64
12-
13- init (name : String , description : String , image : String , attributes : {String : String }) {
14- self .name = name
15- self .description = description
16- self .image = image
17- self .attributes = attributes
18- self .createdAt = getCurrentBlock ().timestamp
1+ access (all ) contract EmojiNFT {
2+
3+ access (all ) event NFTMinted (id : UInt64 , owner : Address , emojiCollage : String )
4+ access (all ) event NFTTransferred (id : UInt64 , from : Address , to : Address )
5+ access (all ) event CollectionCreated (owner : Address )
6+
7+ access (all ) struct Metadata {
8+ access (all ) let name : String
9+ access (all ) let description : String
10+ access (all ) let image : String
11+ access (all ) let attributes : {String : String }
12+ access (all ) let createdAt : UFix64
13+
14+ init (name : String , description : String , image : String , attributes : {String : String }) {
15+ self .name = name
16+ self .description = description
17+ self .image = image
18+ self .attributes = attributes
19+ self .createdAt = getCurrentBlock ().timestamp
20+ }
1921 }
20- }
21-
22- pub resource NFT {
23- pub let id : UInt64
24- pub let emojiCollage : String
25- pub let metadata : Metadata
26- pub let creator : Address
27- pub let royaltyPercentage : UFix64
28-
29- init ( id : UInt64 , emojiCollage : String , metadata : Metadata , creator : Address , royaltyPercentage : UFix64 ) {
30- self .id = id
31- self .emojiCollage = emojiCollage
32- self .metadata = metadata
33- self .creator = creator
34- self . royaltyPercentage = royaltyPercentage
22+
23+ access ( all ) resource NFT {
24+ access ( all ) let id : UInt64
25+ access ( all ) let emojiCollage : String
26+ access ( all ) let metadata : Metadata
27+ access ( all ) let creator : Address
28+ access ( all ) let royaltyPercentage : UFix64
29+
30+ init ( id : UInt64 , emojiCollage : String , metadata : Metadata , creator : Address , royaltyPercentage : UFix64 ) {
31+ self . id = id
32+ self .emojiCollage = emojiCollage
33+ self .metadata = metadata
34+ self .creator = creator
35+ self .royaltyPercentage = royaltyPercentage
36+ }
3537 }
36- }
3738
38- pub resource Collection {
39- pub var ownedNFTs : @{UInt64 : NFT }
40- pub let owner : Address
39+ access ( all ) resource Collection {
40+ access ( all ) var ownedNFTs : @{UInt64 : NFT }
41+ access ( all ) let owner : Address
4142
42- init (owner : Address ) {
43- self .ownedNFTs = {}
44- self .owner = owner
45- emit CollectionCreated (owner : owner )
46- }
43+ init (owner : Address ) {
44+ self .ownedNFTs <- {}
45+ self .owner = owner
46+ emit CollectionCreated (owner : owner )
47+ }
48+
49+ access (all ) fun deposit (token : @NFT ) {
50+ self .ownedNFTs [token .id ] <- ! token
51+ }
52+
53+ access (all ) fun withdraw (id : UInt64 ): @NFT {
54+ let token <- self .ownedNFTs .remove (key : id ) ?? panic (" NFT not found" )
55+ return <- token
56+ }
4757
48- pub fun deposit (token : @NFT ) {
49- self .ownedNFTs [token .id ] = token
58+ access (all ) view fun getNFTs (): [NFT ] {
59+ return self .ownedNFTs .values
60+ }
61+
62+ access (all ) view fun getNFT (id : UInt64 ): &NFT ? {
63+ return &self .ownedNFTs [id ] as &NFT ?
64+ }
5065 }
5166
52- pub fun withdraw (id : UInt64 ): @NFT {
53- let token = self .ownedNFTs .remove (key : id ) ?? panic (" NFT not found" )
54- return token
67+ access (all ) resource interface CollectionPublic {
68+ access (all ) fun deposit (token : @NFT )
69+ access (all ) view fun getNFTs (): [NFT ]
70+ access (all ) view fun getNFT (id : UInt64 ): &NFT ?
5571 }
5672
57- pub fun getNFTs (): [NFT ] {
58- return self .ownedNFTs .values
73+ access (all ) fun createEmptyCollection (): @Collection {
74+ let ownerAddress = getAccount (0x0 ).address // Replace with authorized account
75+ return <- create Collection (owner : ownerAddress )
5976 }
6077
61- pub fun getNFT (id : UInt64 ): &NFT ? {
62- return &self .ownedNFTs [id ] as &NFT ?
78+ access (all ) fun mintNFT (
79+ emojiCollage : String ,
80+ name : String ,
81+ description : String ,
82+ image : String ,
83+ attributes : {String : String },
84+ royaltyPercentage : UFix64
85+ ): @NFT {
86+ let id = self .nextID
87+ self .nextID = self .nextID + 1
88+
89+ let metadata = Metadata (
90+ name : name ,
91+ description : description ,
92+ image : image ,
93+ attributes : attributes
94+ )
95+
96+ let nft <- create NFT (
97+ id : id ,
98+ emojiCollage : emojiCollage ,
99+ metadata : metadata ,
100+ creator : getAccount (0x0 ).address , // Replace with authorized account
101+ royaltyPercentage : royaltyPercentage
102+ )
103+
104+ emit NFTMinted (id : id , owner : getAccount (0x0 ).address , emojiCollage : emojiCollage )
105+
106+ return <- nft
63107 }
64- }
65108
66- pub resource interface CollectionPublic {
67- pub fun deposit (token : @NFT )
68- pub fun getNFTs (): [NFT ]
69- pub fun getNFT (id : UInt64 ): &NFT ?
70- }
109+ access (all ) fun transferNFT (collection : &Collection , id : UInt64 , recipient : Address ) {
110+ let token <- collection .withdraw (id : id )
111+ let recipientCollection = getAccount (recipient )
112+ .capabilities
113+ .borrow <&Collection >(/public/EmojiNFTCollection )
114+ ?? panic (" Collection not found" )
115+
116+ recipientCollection .deposit (token : <- token )
71117
72- pub resource CollectionPublicImpl : CollectionPublic {
73- pub fun deposit (token : @NFT ) {
74- self .ownedNFTs [token .id ] = token
118+ emit NFTTransferred (id : id , from : getAccount (0x0 ).address , to : recipient )
75119 }
76120
77- pub fun getNFTs (): [NFT ] {
78- return self .ownedNFTs .values
121+ access (all ) view fun getNFTMetadata (id : UInt64 ): Metadata ? {
122+ let collection = getAccount (0x0 )
123+ .capabilities
124+ .borrow <&Collection >(/public/EmojiNFTCollection )
125+ ?? panic (" Collection not found" )
126+
127+ let nft = collection .getNFT (id : id )
128+ return nft ?. metadata
79129 }
80130
81- pub fun getNFT (id : UInt64 ): &NFT ? {
82- return &self .ownedNFTs [id ] as &NFT ?
131+ access (all ) var nextID : UInt64
132+ access (all ) var totalSupply : UInt64
133+
134+ init () {
135+ self .nextID = 1
136+ self .totalSupply = 0
83137 }
84- }
85-
86- pub fun createEmptyCollection (): @Collection {
87- return create Collection (owner : self .account .address )
88- }
89-
90- pub fun mintNFT (
91- emojiCollage : String ,
92- name : String ,
93- description : String ,
94- image : String ,
95- attributes : {String : String },
96- royaltyPercentage : UFix64
97- ): @NFT {
98- let id = self .nextID
99- self .nextID = self .nextID + 1
100-
101- let metadata = Metadata (
102- name : name ,
103- description : description ,
104- image : image ,
105- attributes : attributes
106- )
107-
108- let nft = create NFT (
109- id : id ,
110- emojiCollage : emojiCollage ,
111- metadata : metadata ,
112- creator : self .account .address ,
113- royaltyPercentage : royaltyPercentage
114- )
115-
116- emit NFTMinted (id : id , owner : self .account .address , emojiCollage : emojiCollage )
117- return nft
118- }
119-
120- pub fun transferNFT (collection : &Collection , id : UInt64 , recipient : Address ) {
121- let token = collection .withdraw (id : id )
122- let recipientCollection = getAccount (recipient ).getCapability (/public/EmojiNFTCollection )
123- .borrow <&Collection >() ?? panic (" Collection not found" )
124-
125- recipientCollection .deposit (token : token )
126- emit NFTTransferred (id : id , from : self .account .address , to : recipient )
127- }
128-
129- pub fun getNFTMetadata (id : UInt64 ): Metadata ? {
130- let collection = self .account .getCapability (/public/EmojiNFTCollection )
131- .borrow <&Collection >() ?? panic (" Collection not found" )
132-
133- let nft = collection .getNFT (id : id )
134- return nft ?. metadata
135- }
136-
137- pub var nextID : UInt64
138- pub var totalSupply : UInt64
139-
140- init () {
141- self .nextID = 1
142- self .totalSupply = 0
143- }
144- }
138+ }
0 commit comments