第三十三课 如何创建自己的ERC721非同质化资产生物商店?

发布时间:2019年01月31日 价值:20000.00 / 共识:24

1,摘要

加密猫游戏开始,非同质化资产NFT的概念深入人心。不过现在社区中讲概念的多,真正落地发布自己ERC721资产的文章没有看到。辉哥这篇文章就来弥补下这个空缺。
本文的内容包括:
(1)采用REMIX编译本地工程的方式完成合约编译;
(2)采用REMIX IDE完成合约部署;
(3)创建自己的ERC721非同质化资产生物;
(4)转让ERC721非同质化资产生物;
(5)发布自己的ERC721非同质化资产生物商店;

2,实操内容

2.1 环境准备

1) 建立目录,复制工程

针对简单的逻辑执行,辉哥认为采用REMIX编译和部署合约的方式远远比采用TRUFFLE方式方便,同时REMIX也可以加载本地包含import合约关系的复杂工程进行编译。不熟悉的同学可参考文章《第三十二课 如何在Windows环境搭建REMIX本地环境,访问本地目录?》完成配置。ERC721的智能合约就采用OpenZeppelin的ERC721模板合约。
具体的代码架构和分析辉哥就不展示了,有需要源码工程的同学可直接加入辉哥的知识星球下载。

2) 启动REMIX本地编译环境

辉哥的SOLIDITY本地共享目录为”D:\jusanban\doc\50-编码实现\BlockChain”,所以辉哥在WINDOWS下启动命令行,输入以下命令:

remixd -s D:\jusanban\doc\50-编码实现\BlockChain —remix-ide https://remix.ethereum.org

命令行参考截图:

在CHROME浏览器输入https://remix.ethereum.org,点击"Connect to Localhost”的联调按钮,可启动REMIX本地编译环境。

点击”Start to Compile”完成Creature.sol合约编译。

2.2 创建 Creature合约

在辉哥的管理员测试账号”0xd1f7922e8b78cbeb182250753ade8379d1e09949”下,MetaMask的测试网络选择”Rinkeby Test Net”,选择部署的构建参数(代理地址)为”0xf57b2c51ded3a29e6891aba85459d600256cf317”。
点击”Deploy”按钮:

部署成功的交易链接:
https://rinkeby.etherscan.io/tx/0x399cf4c1ed0a7dd52b36612be0c15e56ffce6b119a75024908560461721e38f2
Creature的合约地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1

2.3 创建ERC721资产10个

在账号“0xD1F7922e8b78cBEB182250753ade8379d1E09949”下运行挖矿函数10次,创建10个ERC721资产给辉哥账号。
函数定义: function mintTo(address _to)
执行参数: mintTo(“0xD1F7922e8b78cBEB182250753ade8379d1E09949”)
【执行成功结果】
https://rinkeby.etherscan.io/tx/0x12ed4dc5bca13be134c2258f79d636a4f134a19961444a2b63bc5a23f064f604
查看交易记录,可以看到已从系统地址发布了一个WOLF ERC721给辉哥账号了。

然后再执行9次,再创建其他9个野狼标识资产。
点击辉哥管理账号,可以看到已收到10个ERC721资产。
https://rinkeby.etherscan.io/address/0xd1f7922e8b78cbeb182250753ade8379d1e09949#tokentxnsErc721

2.4 转让资产

1) 转给1#给欧阳哥哥

辉哥把野狼标识资产转给野狼队成员,作为野狼队成员的荣誉特征之一。辉哥首先把珍贵的1#通证转移给欧阳哥哥(地址:0x17b1177E0491D25a13a8329a8D2C46621b6ca19F)。
函数声明:
function safeTransferFrom( address _from, address _to, uint256 _tokenId )
函数调用:safeTransferFrom(“0xd1f7922e8b78cbeb182250753ade8379d1e09949”,”0x17b1177E0491D25a13a8329a8D2C46621b6ca19F”, 1)

转让成功地址:
https://rinkeby.etherscan.io/tx/0x4f56f968748257bf298fd5bcd0e7c2987713bf0086713f410a1ff6dba4af831e
转让成功截图:

2) 转给2#给ELLA小姐姐

辉哥也想给ELLA小姐姐转一个野狼队的标识资产,同时祝她2019年新年快乐。ELLA小姐姐的地址:0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30 。
查看https://onlinehextools.com/convert-utf8-to-hex网站,
可以得知”Happy New Year 2019!”的UTF8的
HEX码为”0x20 0x48 0x61 0x70 0x70 0x79 0x20 0x4e 0x65 0x77 0x20 0x59 0x65 0x61 0x72 0x20 0x32 0x30 0x31 0x39 0x21”,
剔除” 0x”后的输出为:
“0x204861707079204e65772059656172203230313921”。

函数原型: function safeTransferFrom(address _from, address _to,uint256 _tokenId,bytes _data)
调用参数:
safeTransferFrom(“0xd1f7922e8b78cbeb182250753ade8379d1e09949”,”0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30”,2,”0x204861707079204e65772059656172203230313921”)

交易成功的地址:
https://rinkeby.etherscan.io/tx/0x6f234589b641cc00af7e54afa757c00427cf3379c01411e35109522820e9b2fb

转移成功截图和新年祝福语:

2.5 创建商店

使用OpenSea可创建非同质化资产交易商店。该创建者将在OpenSea上填充您的所有资产,并为您的项目提供专用的店面页面。
点击地址:https://rinkeby.opensea.io/get-listed/step-two

1),输入本次智能合约地址

智能合约地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1
点击”Commit”按钮:

2),导入资产

进入第二步,导入野狼队的10个ERC721资产。

  1. Currently loading 4 of 11 items...
  2. This might take a while so take a break and come back a bit later. In fact, just start a conversation on our [discord](https://discord.gg/ga8EJbv), read our [wikis](https://cryptokitties.opensea.io/), or browse our [marketplace](https://rinkeby.opensea.io/assets).

3),查看店面

跳转到我的店面主页:
https://rinkeby.opensea.io/category/wildwolfteam

4),转移给大明

艺术家大明账号地址:0x8fc02f03c15179f8C6D37C3a29FE7A338DC68192 。辉哥通过店面转移一个资产3#给大明。

输入大明地址,点击”Transfer”按钮就转移给大明了。

5),标价出售

把第4个资产标价为0.1 WETH,用于定价出售。
https://rinkeby.opensea.io/assets/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/4
点击”SELL”按钮:

选择固定价格0.1 ETH出售,点击”Post Your List”:

点击授权后,等候有心人点击购买了。

2.6 资产形象优化

这个店铺资产的图形是采用默认的海洋生物图标,并不是辉哥期望的野狼队标识。
这个需要配置每个资产的MetaData元素。
例如在浏览器输入1# ERC721资产的URI:
https://rinkeby-api.opensea.io/api/v1/asset/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1/
可以返回由OpenSea配置的ERC721资产特性信息。
辉哥会在下一篇文章详细介绍如何修改ERC721的MetaDATA,让它们跟野狼队的标识LOGO更加匹配。

  1. {
  2. "token_id": "1",
  3. "image_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1.png",
  4. "image_preview_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1-preview/1.png",
  5. "image_thumbnail_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1-thumbnail/1.png",
  6. "image_original_url": "https://storage.googleapis.com/opensea-prod.appspot.com/creature/1.png",
  7. "animation_url": null,
  8. "name": "Sprinkles Fisherton",
  9. "description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
  10. "external_link": "https://openseacreatures.io/1",
  11. "asset_contract": {
  12. "address": "0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1",
  13. "name": "Wild Wolf Team",
  14. "symbol": "WOLF",
  15. "image_url": null,
  16. "featured_image_url": null,
  17. "featured": false,
  18. "description": null,
  19. "external_link": null,
  20. "wiki_link": null,
  21. "stats": {
  22. "seven_day_volume": 0,
  23. "seven_day_change": 0,
  24. "total_volume": 0,
  25. "count": 10,
  26. "num_owners": 3,
  27. "market_cap": 0,
  28. "average_price": 0,
  29. "items_sold": 0
  30. },
  31. "traits": {
  32. "aqua_power": {
  33. "min": 10,
  34. "max": 40
  35. },
  36. "stamina": {
  37. "min": 1.2,
  38. "max": 90.2
  39. },
  40. "level": {
  41. "min": 2,
  42. "max": 8
  43. },
  44. "generation": {
  45. "min": 1,
  46. "max": 2
  47. },
  48. "stamina_increase": {
  49. "min": 5,
  50. "max": 15
  51. },
  52. "personality": {
  53. "sad": 1,
  54. "boring": 1,
  55. "sleepy": 1,
  56. "happy": 1
  57. },
  58. "mouth": {
  59. "pleased": 1,
  60. "surprised": 1,
  61. "happy": 1,
  62. "cute": 1
  63. },
  64. "eyes": {
  65. "content": 1,
  66. "joy": 1,
  67. "wink": 1,
  68. "big": 1,
  69. "sleepy": 1
  70. },
  71. "base": {
  72. "crab": 1,
  73. "goldfish": 1,
  74. "narwhal": 1,
  75. "jellyfish": 1,
  76. "starfish": 1,
  77. "tealfish": 1
  78. }
  79. },
  80. "hidden": true,
  81. "nft_version": "3.0",
  82. "schema_name": "ERC721",
  83. "display_data": {
  84. "images": [
  85. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/10.png",
  86. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/9.png",
  87. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/8.png",
  88. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/7.png",
  89. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/6.png",
  90. "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/5.png"
  91. ]
  92. },
  93. "short_description": null,
  94. "total_supply": null,
  95. "owner": null,
  96. "buyer_fee_basis_points": 0,
  97. "seller_fee_basis_points": 250
  98. },
  99. "owner": {
  100. "user": null,
  101. "profile_img_url": "https://storage.googleapis.com/opensea-static/opensea-profile/3.png",
  102. "address": "0x17b1177e0491d25a13a8329a8d2c46621b6ca19f",
  103. "config": ""
  104. },
  105. "permalink": "https://rinkeby.opensea.io/assets/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1",
  106. "background_color": null,
  107. "auctions": [],
  108. "sell_orders": null,
  109. "traits": [
  110. {
  111. "trait_type": "generation",
  112. "value": 2,
  113. "display_type": "number",
  114. "max_value": null,
  115. "trait_count": 3,
  116. "order": null
  117. },
  118. {
  119. "trait_type": "stamina_increase",
  120. "value": 10,
  121. "display_type": "boost_percentage",
  122. "max_value": null,
  123. "trait_count": 4,
  124. "order": null
  125. },
  126. {
  127. "trait_type": "aqua_power",
  128. "value": 40,
  129. "display_type": "boost_number",
  130. "max_value": null,
  131. "trait_count": 4,
  132. "order": null
  133. },
  134. {
  135. "trait_type": "personality",
  136. "value": "sad",
  137. "display_type": null,
  138. "max_value": null,
  139. "trait_count": 3,
  140. "order": null
  141. },
  142. {
  143. "trait_type": "stamina",
  144. "value": 2.3,
  145. "display_type": null,
  146. "max_value": null,
  147. "trait_count": 2,
  148. "order": null
  149. },
  150. {
  151. "trait_type": "level",
  152. "value": 2,
  153. "display_type": null,
  154. "max_value": null,
  155. "trait_count": 2,
  156. "order": null
  157. },
  158. {
  159. "trait_type": "mouth",
  160. "value": "surprised",
  161. "display_type": null,
  162. "max_value": null,
  163. "trait_count": 3,
  164. "order": null
  165. },
  166. {
  167. "trait_type": "eyes",
  168. "value": "joy",
  169. "display_type": null,
  170. "max_value": null,
  171. "trait_count": 2,
  172. "order": null
  173. },
  174. {
  175. "trait_type": "base",
  176. "value": "starfish",
  177. "display_type": null,
  178. "max_value": null,
  179. "trait_count": 2,
  180. "order": null
  181. }
  182. ],
  183. "last_sale": null,
  184. "num_sales": 0,
  185. "top_bid": null,
  186. "current_price": null,
  187. "current_escrow_price": null,
  188. "listing_date": null,
  189. "is_presale": false,
  190. "related_assets": [],
  191. "orders": [],
  192. "supports_wyvern": true,
  193. "visitor_stats": {
  194. "rank": 3
  195. }
  196. }

3,参考

1)开发文档导航
2) 在OpenSea登记Rinkeby网络的ERC721资产

  • 分享 收藏
0 条评论
  • 这篇文章暂无评论,赶紧评论一下吧~