Contract con_aispangeart


Contract Code


  
1 collection_name = Variable()
2 collection_owner = Variable()
3 collection_nfts = Hash(default_value=0)
4 collection_balances = Hash(default_value=0)
5 collection_balances_approvals = Hash(default_value=0)
6
7 @construct
8 def seed():
9 collection_name.set("AIspangeART")
10 collection_owner.set(ctx.caller)
11
12 @export
13 def mint_nft(name: str, description: str, ipfs_image_url: str, metadata: dict, amount: int):
14 assert name != "", "Name cannot be empty"
15 assert collection_nfts[name] == 0, "Name already exists"
16 assert amount > 0, "You cannot transfer negative amounts"
17 assert collection_owner.get() == ctx.caller, "Only the collection owner can mint NFTs"
18
19 collection_nfts[name] = {"description": description, "ipfs_image_url": ipfs_image_url, "metadata": metadata, "amount": amount}
20 collection_balances[ctx.caller, name] = amount
21
22 @export
23 def transfer(name: str, amount:int, to: str):
24 assert amount > 0, "You cannot transfer negative amounts"
25 assert name != "", "Please specify the name of the NFT you want to transfer"
26 assert collection_balances[ctx.caller, name] >= amount, "You dont have enough NFTs to send"
27
28 collection_balances[ctx.caller, name] -= amount
29 collection_balances[to, name] += amount # Adds amount to receiver
30
31 @export
32 def approve(amount: int, name: str, to: str):
33 assert amount > 0, "Cannot approve negative amounts"
34
35 collection_balances_approvals[ctx.caller, to, name] += amount
36
37 @export
38 def transfer_from(name:str, amount:int, to: str, main_account: str):
39 assert amount > 0, "Cannot send negative balances!"
40
41 assert collection_balances_approvals[main_account, to, name] >= amount, "Not enough NFTs approved to send! You have {} and are trying to spend {}".format(collection_balances_approvals[main_account, to, name], amount)
42 assert collection_balances[main_account, name] >= amount, "Not enough NFTs to send!"
43
44 collection_balances_approvals[main_account, to, name] -= amount
45 collection_balances[main_account, name] -= amount
46
47 collection_balances[to, name] += amount
48

Byte Code

e3000000000000000000000000070000004000000073bc00000065006400640164028d025a0165006400640364028d025a02650364046400640564068d035a04650364046400640764068d035a05650364046400640864068d035a066409640a84005a07650864008301650965096509650a650b640b9c05640c640d840483015a0c6508640083016509650b6509640e9c03640f6410840483015a0d650864008301650b6509650964119c0364126413840483015a0e6508640083016509650b6509650964149c0464156416840483015a0f641753002918da0f636f6e5f61697370616e6765617274da0f636f6c6c656374696f6e5f6e616d652902da08636f6e7472616374da046e616d65da10636f6c6c656374696f6e5f6f776e6572e900000000da0f636f6c6c656374696f6e5f6e6674732903da0d64656661756c745f76616c756572030000007204000000da13636f6c6c656374696f6e5f62616c616e636573da1d636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73630000000000000000000000000200000043000000731a00000074006a0164018301010074026a0174036a04830101006400530029024eda0b41497370616e67654152542905da115f5f636f6c6c656374696f6e5f6e616d65da03736574da125f5f636f6c6c656374696f6e5f6f776e6572da03637478da0663616c6c6572a90072110000007211000000da00da045f5f5f5f0d000000730400000000010a01721300000029057204000000da0b6465736372697074696f6eda0e697066735f696d6167655f75726cda086d65746164617461da06616d6f756e74630500000000000000050000000500000043000000736e0000007c0064016b037310740064028301820174017c00190064036b02732474006404830182017c0464036b047334740064058301820174026a03830074046a056b02734a74006406830182017c017c027c037c0464079c0474017c003c007c04740674046a057c0066023c006400530029084e72120000007a144e616d652063616e6e6f7420626520656d70747972060000007a134e616d6520616c7265616479206578697374737a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e74737a274f6e6c792074686520636f6c6c656374696f6e206f776e65722063616e206d696e74204e465473290472140000007215000000721600000072170000002907da0e417373657274696f6e4572726f72da115f5f636f6c6c656374696f6e5f6e667473720e000000da03676574720f0000007210000000da155f5f636f6c6c656374696f6e5f62616c616e636573290572040000007214000000721500000072160000007217000000721100000072110000007212000000da086d696e745f6e667412000000731000000000031001140110010601100102011001721c000000290372040000007217000000da02746f63030000000000000003000000040000004300000073680000007c0164016b04731074006402830182017c0064036b0373207400640483018201740174026a037c00660219007c016b05733a7400640583018201740174026a037c006602050019007c01380003003c0074017c027c006602050019007c01370003003c006400530029064e72060000007a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e747372120000007a37506c65617365207370656369667920746865206e616d65206f6620746865204e465420796f752077616e7420746f207472616e736665727a21596f7520646f6e74206861766520656e6f756768204e46547320746f2073656e6429047218000000721b000000720f0000007210000000290372040000007217000000721d000000721100000072110000007212000000da087472616e736665721f000000730c0000000002100110010c010e011601721e000000290372170000007204000000721d000000630300000000000000030000000400000043000000732c0000007c0064016b0473107400640283018201740174026a037c027c016603050019007c00370003003c006400530029034e72060000007a1f43616e6e6f7420617070726f7665206e6567617469766520616d6f756e747329047218000000da1f5f5f636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73720f0000007210000000290372170000007204000000721d000000721100000072110000007212000000da07617070726f7665290000007304000000000210017220000000290472040000007217000000721d000000da0c6d61696e5f6163636f756e7463040000000000000004000000060000004300000073960000007c0164016b047310740064028301820174017c037c027c00660319007c016b05733c740064036a0274017c037c027c00660319007c0183028301820174037c037c00660219007c016b057354740064048301820174017c037c027c006603050019007c01380003003c0074037c037c006602050019007c01380003003c0074037c027c006602050019007c01370003003c006400530029054e72060000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a484e6f7420656e6f756768204e46547320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a184e6f7420656e6f756768204e46547320746f2073656e642129047218000000721f000000da06666f726d6174721b000000290472040000007217000000721d0000007221000000721100000072110000007212000000da0d7472616e736665725f66726f6d2f0000007312000000000210010c010c0114010a010e011601140172230000004e2910da085661726961626c65720c000000720e000000da04486173687219000000721b000000721f0000007213000000da085f5f6578706f7274da03737472da0464696374da03696e74721c000000721e000000722000000072230000007211000000721100000072110000007212000000da083c6d6f64756c653e0100000073240000000c0204010801060108010601080104010a03080506010601120b06011409060114050601