Contract con_lamden_realm_v3


Contract Code


  
1 I = importlib
2 collection_name = Variable()
3 collection_owner = Variable()
4 collection_nfts = Hash(default_value=0)
5 collection_balances = Hash(default_value=0)
6 collection_balances_approvals = Hash(default_value=0)
7 crafting_contract = Variable()
8
9 @construct
10 def seed():
11 collection_name.set("The Lamden Realm")
12 collection_owner.set(ctx.caller)
13 crafting_contract.set("con_crafter_v9")
14
15 @export
16 def mint_nft(name: str, description: str, ipfs_image_url: str, metadata: dict, amount: int):
17 assert name != "", "Name cannot be empty"
18 assert collection_nfts[name] == 0, "Name already exists"
19 assert amount > 0, "You cannot transfer negative amounts"
20 assert collection_owner.get() == ctx.caller or ctx.caller == crafting_contract.get(), "Only the collection owner can mint NFTs"
21 collection_nfts[name] = {"description": description, "ipfs_image_url": ipfs_image_url, "metadata": metadata, "amount": amount}
22 collection_balances[ctx.caller, name] = amount
23
24 @export
25 def transfer(name: str, amount:int, to: str):
26 assert amount > 0, "You cannot transfer negative amounts"
27 assert name != "", "Please specify the name of the NFT you want to transfer"
28 assert collection_balances[ctx.caller, name] >= amount, "You dont have enough NFTs to send"
29 collection_balances[ctx.caller, name] -= amount
30 collection_balances[to, name] += amount # Adds amount to receiver
31
32 @export
33 def approve(amount: int, name: str, to: str):
34 assert amount > 0, "Cannot approve negative amounts"
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 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)
41 assert collection_balances[main_account, name] >= amount, "Not enough NFTs to send!"
42 collection_balances_approvals[main_account, to, name] -= amount
43 collection_balances[main_account, name] -= amount
44 collection_balances[to, name] += amount
45
46 @export
47 def set_crafting_contract(contract: str):
48 assert ctx.caller == collection_owner.get(), "Only the collection owner can set the crafting contract"
49 crafting_contract.set(contract)
50

Byte Code

e3000000000000000000000000070000004000000073e200000065005a0165026400640164028d025a0365026400640364028d025a04650564046400640564068d035a06650564046400640764068d035a07650564046400640864068d035a0865026400640964028d025a09640a640b84005a0a650b64008301650c650c650c650d650e640c9c05640d640e840483015a0f650b64008301650c650e650c640f9c0364106411840483015a10650b64008301650e650c650c64129c0364136414840483015a11650b64008301650c650e650c650c64159c0464166417840483015a12650b64008301650c64189c016419641a840483015a13641b5300291cda13636f6e5f6c616d64656e5f7265616c6d5f7633da0f636f6c6c656374696f6e5f6e616d652902da08636f6e7472616374da046e616d65da10636f6c6c656374696f6e5f6f776e6572e900000000da0f636f6c6c656374696f6e5f6e6674732903da0d64656661756c745f76616c756572030000007204000000da13636f6c6c656374696f6e5f62616c616e636573da1d636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c73da116372616674696e675f636f6e7472616374630000000000000000000000000200000043000000732400000074006a0164018301010074026a0174036a048301010074056a016402830101006400530029034e7a10546865204c616d64656e205265616c6dda0e636f6e5f637261667465725f76392906da115f5f636f6c6c656374696f6e5f6e616d65da03736574da125f5f636f6c6c656374696f6e5f6f776e6572da03637478da0663616c6c6572da135f5f6372616674696e675f636f6e7472616374a90072130000007213000000da00da045f5f5f5f10000000730600000000010a010c01721500000029057204000000da0b6465736372697074696f6eda0e697066735f696d6167655f75726cda086d65746164617461da06616d6f756e74630500000000000000050000000500000043000000737c0000007c0064016b037310740064028301820174017c00190064036b02732474006404830182017c0464036b047334740064058301820174026a03830074046a056b02735874046a0574066a0383006b02735874006406830182017c017c027c037c0464079c0474017c003c007c04740774046a057c0066023c006400530029084e72140000007a144e616d652063616e6e6f7420626520656d70747972060000007a134e616d6520616c7265616479206578697374737a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e74737a274f6e6c792074686520636f6c6c656374696f6e206f776e65722063616e206d696e74204e465473290472160000007217000000721800000072190000002908da0e417373657274696f6e4572726f72da115f5f636f6c6c656374696f6e5f6e667473720f000000da03676574721000000072110000007212000000da155f5f636f6c6c656374696f6e5f62616c616e636573290572040000007216000000721700000072180000007219000000721300000072130000007214000000da086d696e745f6e6674160000007312000000000310011401100106011801060102011001721e000000290372040000007219000000da02746f63030000000000000003000000040000004300000073680000007c0164016b04731074006402830182017c0064036b0373207400640483018201740174026a037c00660219007c016b05733a7400640583018201740174026a037c006602050019007c01380003003c0074017c027c006602050019007c01370003003c006400530029064e72060000007a24596f752063616e6e6f74207472616e73666572206e6567617469766520616d6f756e747372140000007a37506c65617365207370656369667920746865206e616d65206f6620746865204e465420796f752077616e7420746f207472616e736665727a21596f7520646f6e74206861766520656e6f756768204e46547320746f2073656e642904721a000000721d00000072100000007211000000290372040000007219000000721f000000721300000072130000007214000000da087472616e7366657224000000730c0000000002100110010c010e0116017220000000290372190000007204000000721f000000630300000000000000030000000400000043000000732c0000007c0064016b0473107400640283018201740174026a037c027c016603050019007c00370003003c006400530029034e72060000007a1f43616e6e6f7420617070726f7665206e6567617469766520616d6f756e74732904721a000000da1f5f5f636f6c6c656374696f6e5f62616c616e6365735f617070726f76616c7372100000007211000000290372190000007204000000721f000000721300000072130000007214000000da07617070726f76652e0000007304000000000210017222000000290472040000007219000000721f000000da0c6d61696e5f6163636f756e7463040000000000000004000000060000004300000073960000007c0164016b047310740064028301820174017c037c027c00660319007c016b05733c740064036a0274017c037c027c00660319007c0183028301820174037c037c00660219007c016b057354740064048301820174017c037c027c006603050019007c01380003003c0074037c037c006602050019007c01380003003c0074037c027c006602050019007c01370003003c006400530029054e72060000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a484e6f7420656e6f756768204e46547320617070726f76656420746f2073656e642120596f752068617665207b7d20616e642061726520747279696e6720746f207370656e64207b7d7a184e6f7420656e6f756768204e46547320746f2073656e64212904721a0000007221000000da06666f726d6174721d000000290472040000007219000000721f0000007223000000721300000072130000007214000000da0d7472616e736665725f66726f6d340000007312000000000210010c010c0114010a010e0116011401722500000029017203000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a374f6e6c792074686520636f6c6c656374696f6e206f776e65722063616e2073657420746865206372616674696e6720636f6e7472616374290772100000007211000000720f000000721c000000721a0000007212000000720e00000029017203000000721300000072130000007214000000da157365745f6372616674696e675f636f6e747261637441000000730600000000021001060172260000004e2914da09696d706f72746c6962da0149da085661726961626c65720d000000720f000000da0448617368721b000000721d000000722100000072120000007215000000da085f5f6578706f7274da03737472da0464696374da03696e74721e00000072200000007222000000722500000072260000007213000000721300000072130000007214000000da083c6d6f64756c653e010000007330000000040104010801040108010601080104010a0104010a0104010803080606010601120c06011409060114050601160c0601